1 | /* |
---|
2 | * Copyright (c) 1983 Regents of the University of California. |
---|
3 | * All rights reserved. The Berkeley software License Agreement |
---|
4 | * specifies the terms and conditions for redistribution. |
---|
5 | */ |
---|
6 | |
---|
7 | #ifndef lint |
---|
8 | static char sccsid[] = "@(#)displayq.c 5.1 (Berkeley) 6/6/85"; |
---|
9 | #endif not lint |
---|
10 | |
---|
11 | /* |
---|
12 | * Routines to display the state of the queue. |
---|
13 | */ |
---|
14 | |
---|
15 | #include "lp.h" |
---|
16 | |
---|
17 | #define JOBCOL 40 /* column for job # in -l format */ |
---|
18 | #define OWNCOL 7 /* start of Owner column in normal */ |
---|
19 | #define SIZCOL 62 /* start of Size column in normal */ |
---|
20 | |
---|
21 | /* |
---|
22 | * Stuff for handling job specifications |
---|
23 | */ |
---|
24 | extern char *user[]; /* users to process */ |
---|
25 | extern int users; /* # of users in user array */ |
---|
26 | extern int requ[]; /* job number of spool entries */ |
---|
27 | extern int requests; /* # of spool requests */ |
---|
28 | |
---|
29 | int lflag; /* long output option */ |
---|
30 | int rank; /* order to be printed (-1=none, 0=active) */ |
---|
31 | long totsize; /* total print job size in bytes */ |
---|
32 | int sendtorem; /* are we sending to a remote? */ |
---|
33 | |
---|
34 | /* |
---|
35 | * Display the current state of the queue. Format = 1 if long format. |
---|
36 | */ |
---|
37 | displayq(format) |
---|
38 | int format; |
---|
39 | { |
---|
40 | register int i, fd; |
---|
41 | int rem_fils; |
---|
42 | char *tmpptr; |
---|
43 | struct hostent *hp; |
---|
44 | |
---|
45 | char name[MAXHOSTNAMELEN]; |
---|
46 | register char *cp; |
---|
47 | lflag = format; |
---|
48 | totsize = 0; |
---|
49 | rank = -1; |
---|
50 | rem_fils = 0; |
---|
51 | |
---|
52 | #ifdef HESIOD |
---|
53 | if ((i = pgetent(line, printer)) <= 0) { |
---|
54 | if (pralias(alibuf, printer)) |
---|
55 | printer = alibuf; |
---|
56 | if ((i = hpgetent(line, printer)) < 1) |
---|
57 | fatal("unknown printer"); |
---|
58 | } |
---|
59 | #else |
---|
60 | if ((i = pgetent(line, printer)) < 0) { |
---|
61 | fatal("cannot open printer description file"); |
---|
62 | } else if (i == 0) |
---|
63 | fatal("unknown printer"); |
---|
64 | #endif HESIOD |
---|
65 | if ((LP = pgetstr("lp", &bp)) == NULL) |
---|
66 | LP = DEFDEVLP; |
---|
67 | if ((RP = pgetstr("rp", &bp)) == NULL) |
---|
68 | RP = LP; |
---|
69 | if ((RM = pgetstr("rm", &bp)) == NULL) { |
---|
70 | gethostname(name,sizeof(name)); |
---|
71 | if (hp = gethostbyname(name)) |
---|
72 | (void) strcpy(name,hp->h_name); |
---|
73 | RP = LP; |
---|
74 | RM = name; |
---|
75 | } |
---|
76 | |
---|
77 | /* |
---|
78 | * Print the queue on the remote machine |
---|
79 | */ |
---|
80 | |
---|
81 | sendtorem++; |
---|
82 | (void) sprintf(line, "%c%s", format + '\3', RP); |
---|
83 | cp = line; |
---|
84 | for (i = 0; i < requests; i++) { |
---|
85 | cp += strlen(cp); |
---|
86 | (void) sprintf(cp, " %d", requ[i]); |
---|
87 | } |
---|
88 | for (i = 0; i < users; i++) { |
---|
89 | cp += strlen(cp); |
---|
90 | *cp++ = ' '; |
---|
91 | (void) strcpy(cp, user[i]); |
---|
92 | } |
---|
93 | strcat(line, "\n"); |
---|
94 | fd = getport(RM); |
---|
95 | if (fd < 0) { |
---|
96 | if (from != host) |
---|
97 | printf("%s: ", host); |
---|
98 | printf("unable to connect to %s (for %s)\n", RM, RP); |
---|
99 | } else { |
---|
100 | printf("%s... ", RM); fflush(stdout); |
---|
101 | i = strlen(line); |
---|
102 | if (write(fd, line, i) != i) |
---|
103 | fatal("Lost connection"); |
---|
104 | rem_fils = -1; |
---|
105 | while ((i = read(fd, line, sizeof(line))) > 0) { |
---|
106 | (void) fwrite(line, 1, i, stdout); |
---|
107 | for (tmpptr = line; |
---|
108 | tmpptr = index(tmpptr,'\n'); ) { |
---|
109 | rem_fils++; |
---|
110 | tmpptr++; |
---|
111 | } |
---|
112 | } |
---|
113 | (void) close(fd); |
---|
114 | } |
---|
115 | return(rem_fils); |
---|
116 | } |
---|