diff options
Diffstat (limited to 'printutils/lpq.c')
-rw-r--r-- | printutils/lpq.c | 108 |
1 files changed, 0 insertions, 108 deletions
diff --git a/printutils/lpq.c b/printutils/lpq.c deleted file mode 100644 index ce9a10cb3..000000000 --- a/printutils/lpq.c +++ /dev/null | |||
@@ -1,108 +0,0 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * Copyright 2008 Walter Harms (WHarms@bfs.de) | ||
4 | * | ||
5 | * Licensed under the GPL v2, see the file LICENSE in this tarball. | ||
6 | */ | ||
7 | #include "libbb.h" | ||
8 | #include "lpr.h" | ||
9 | |||
10 | /* | ||
11 | this is a *very* resticted form of lpq | ||
12 | since we do not read /etc/printcap (and never will) | ||
13 | we can only do things rfc1179 allows: | ||
14 | - show print jobs for a given queue long/short form | ||
15 | - remove a job from a given queue | ||
16 | |||
17 | -P <queue> | ||
18 | -s short | ||
19 | -d delete job | ||
20 | -f force any waiting job to be printed | ||
21 | */ | ||
22 | enum { | ||
23 | LPQ_SHORT = 1 << 0, | ||
24 | LPQ_DELETE = 1 << 1, | ||
25 | LPQ_FORCE = 1 << 2, | ||
26 | LPQ_P = 1 << 3, | ||
27 | LPQ_t = 1 << 4, | ||
28 | }; | ||
29 | |||
30 | /* | ||
31 | print everthing that comes | ||
32 | */ | ||
33 | static void get_answer(int sockfd) | ||
34 | { | ||
35 | char buf[80]; | ||
36 | int n; | ||
37 | |||
38 | buf[0] = '\n'; | ||
39 | while (1) { | ||
40 | n = safe_read(sockfd, buf, sizeof(buf)); | ||
41 | if (n <= 0) | ||
42 | break; | ||
43 | full_write(STDOUT_FILENO, buf, n); | ||
44 | buf[0] = buf[n-1]; /* last written char */ | ||
45 | } | ||
46 | |||
47 | /* Don't leave last output line unterminated */ | ||
48 | if (buf[0] != '\n') | ||
49 | full_write(STDOUT_FILENO, "\n", 1); | ||
50 | } | ||
51 | |||
52 | /* | ||
53 | is this too simple ? | ||
54 | should we support more ENV ? | ||
55 | PRINTER, LPDEST, NPRINTER, NGPRINTER | ||
56 | */ | ||
57 | int lpq_main(int argc, char *argv[]) MAIN_EXTERNALLY_VISIBLE; | ||
58 | int lpq_main(int argc, char *argv[]) | ||
59 | { | ||
60 | struct netprint netprint; | ||
61 | const char *netopt; | ||
62 | const char *delopt = "0"; | ||
63 | int sockfd = sockfd; /* for compiler */ | ||
64 | unsigned opt; | ||
65 | int delay; /* delay in [s] */ | ||
66 | |||
67 | netopt = NULL; | ||
68 | opt = getopt32(argv, "sdfP:t:", &netopt, &delopt); | ||
69 | argv += optind; | ||
70 | delay = xatoi_u(delopt); | ||
71 | parse_prt(netopt, &netprint); | ||
72 | |||
73 | /* do connect */ | ||
74 | if (opt & (LPQ_FORCE|LPQ_DELETE)) | ||
75 | sockfd = xconnect_stream(netprint.lsa); | ||
76 | |||
77 | /* force printing of every job still in queue */ | ||
78 | if (opt & LPQ_FORCE) { | ||
79 | fdprintf(sockfd, "\x1" "%s", netprint.queue); | ||
80 | get_answer(sockfd); | ||
81 | return EXIT_SUCCESS; | ||
82 | } | ||
83 | |||
84 | /* delete job (better a list of jobs). username is now LOGNAME */ | ||
85 | if (opt & LPQ_DELETE) { | ||
86 | while (*argv) { | ||
87 | fdprintf(sockfd, "\x5" "%s %s %s", | ||
88 | netprint.queue, | ||
89 | getenv("LOGNAME"), /* FIXME - may be NULL? */ | ||
90 | *argv); | ||
91 | get_answer(sockfd); | ||
92 | argv++; | ||
93 | } | ||
94 | return EXIT_SUCCESS; | ||
95 | } | ||
96 | |||
97 | do { | ||
98 | sockfd = xconnect_stream(netprint.lsa); | ||
99 | fdprintf(sockfd, "%c%s\n", (opt & LPQ_SHORT) ? 3 : 4, | ||
100 | netprint.queue); | ||
101 | |||
102 | get_answer(sockfd); | ||
103 | close(sockfd); | ||
104 | sleep(delay); | ||
105 | } while (delay != 0); | ||
106 | |||
107 | return EXIT_SUCCESS; | ||
108 | } | ||