]>
git.ipfire.org Git - thirdparty/util-linux.git/blob - sys-utils/tunelp.c
1 /****************************************************************************\
2 * Copyright (C) 1992-1997 Michael K. Johnson, johnsonm@redhat.com *
4 * This file is licensed under the terms of the GNU General *
5 * Public License, version 2, or any later version. See file COPYING *
6 * for information on distribution conditions. *
7 \****************************************************************************/
11 * Revision 1.9 1998/06/08 19:37:11 janl
12 * Thus compiles tunelp with 2.1.103 kernels
14 * Revision 1.8 1997/07/06 00:14:06 aebr
15 * Fixes to silence -Wall.
17 * Revision 1.7 1997/06/20 16:10:38 janl
18 * tunelp refreshed from authors archive.
20 * Revision 1.9 1997/06/20 12:56:43 johnsonm
21 * Finished fixing license terms.
23 * Revision 1.8 1997/06/20 12:34:59 johnsonm
24 * Fixed copyright and license.
26 * Revision 1.7 1995/03/29 11:16:23 johnsonm
29 * Revision 1.6 1995/03/29 11:12:15 johnsonm
30 * Added third argument to ioctl needed with new kernels
32 * Revision 1.5 1995/01/13 10:33:43 johnsonm
33 * Chris's changes for new ioctl numbers and backwards compatibility
34 * and the reset ioctl.
36 * Revision 1.4 1995/01/03 17:42:14 johnsonm
37 * -s isn't supposed to take an argument; removed : after s in getopt...
39 * Revision 1.3 1995/01/03 07:36:49 johnsonm
42 * Revision 1.2 1995/01/03 07:33:44 johnsonm
43 * revisions for lp driver updates in Linux 1.1.76
45 * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
46 * - added Native Language Support
48 * 1999-05-07 Merged LPTRUSTIRQ patch by Andrea Arcangeli (1998/11/29), aeb
55 /* #include <linux/fs.h> */
56 #include <sys/ioctl.h>
58 #include <sys/types.h>
74 print_usage(char *progname
) {
75 printf(_("Usage: %s <device> [ -i <IRQ> | -t <TIME> | -c <CHARS> | -w <WAIT> | \n"
76 " -a [on|off] | -o [on|off] | -C [on|off] | -q [on|off] | -s | \n"
83 print_version(char *progname
) {
84 printf("%s (%s)\n", progname
, PACKAGE_STRING
);
90 if(!(ptr
= (void*)malloc(size
))) {
91 perror(_("malloc error"));
97 static char *progname
;
102 if (!(sscanf(val
, "%ld", &ret
) == 1)) {
103 fprintf(stderr
, _("%s: bad value\n"), progname
);
111 get_onoff(char *val
) {
112 if (!strncasecmp("on", val
, 2))
118 main (int argc
, char ** argv
) {
119 int c
, fd
, irq
, status
, show_irq
, offset
= 0, retval
;
122 struct command
*cmds
, *cmdst
;
125 if ((p
= strrchr(progname
, '/')) != NULL
)
128 setlocale(LC_ALL
, "");
129 bindtextdomain(PACKAGE
, LOCALEDIR
);
132 if (argc
< 2) print_usage(progname
);
134 cmdst
= cmds
= mylloc(sizeof(struct command
));
138 while ((c
= getopt(argc
, argv
, "t:c:w:a:i:ho:C:sq:rT:vV")) != -1) {
141 print_usage(progname
);
145 cmds
->val
= get_val(optarg
);
146 cmds
->next
= mylloc(sizeof(struct command
));
147 cmds
= cmds
->next
; cmds
->next
= 0;
151 cmds
->val
= get_val(optarg
);
152 cmds
->next
= mylloc(sizeof(struct command
));
153 cmds
= cmds
->next
; cmds
->next
= 0;
157 cmds
->val
= get_val(optarg
);
158 cmds
->next
= mylloc(sizeof(struct command
));
159 cmds
= cmds
->next
; cmds
->next
= 0;
163 cmds
->val
= get_val(optarg
);
164 cmds
->next
= mylloc(sizeof(struct command
));
165 cmds
= cmds
->next
; cmds
->next
= 0;
169 cmds
->val
= get_onoff(optarg
);
170 cmds
->next
= mylloc(sizeof(struct command
));
171 cmds
= cmds
->next
; cmds
->next
= 0;
174 if (get_onoff(optarg
)) {
181 cmds
->op
= LPABORTOPEN
;
182 cmds
->val
= get_onoff(optarg
);
183 cmds
->next
= mylloc(sizeof(struct command
));
184 cmds
= cmds
->next
; cmds
->next
= 0;
187 cmds
->op
= LPCAREFUL
;
188 cmds
->val
= get_onoff(optarg
);
189 cmds
->next
= mylloc(sizeof(struct command
));
190 cmds
= cmds
->next
; cmds
->next
= 0;
194 cmds
->op
= LPGETSTATUS
;
196 cmds
->next
= mylloc(sizeof(struct command
));
197 cmds
= cmds
->next
; cmds
->next
= 0;
204 cmds
->next
= mylloc(sizeof(struct command
));
205 cmds
= cmds
->next
; cmds
->next
= 0;
210 /* Note: this will do the wrong thing on 2.0.36 when compiled under 2.2.x */
211 cmds
->op
= LPTRUSTIRQ
;
212 cmds
->val
= get_onoff(optarg
);
213 cmds
->next
= mylloc(sizeof(struct command
));
214 cmds
= cmds
->next
; cmds
->next
= 0;
219 print_version(progname
);
222 print_usage(progname
);
226 if (optind
!= argc
-1)
227 print_usage(progname
);
229 filename
= strdup(argv
[optind
]);
230 fd
= open(filename
, O_WRONLY
|O_NONBLOCK
, 0);
231 /* Need to open O_NONBLOCK in case ABORTOPEN is already set and
232 printer is off or off-line or in an error condition. Otherwise
241 if(!S_ISCHR(statbuf
.st_mode
)) {
242 printf(_("%s: %s not an lp device.\n"), argv
[0], filename
);
243 print_usage(progname
);
246 /* Allow for binaries compiled under a new kernel to work on the old ones */
247 /* The irq argument to ioctl isn't touched by the old kernels, but we don't */
248 /* want to cause the kernel to complain if we are using a new kernel */
249 if (LPGETIRQ
>= 0x0600 && ioctl(fd
, LPGETIRQ
, &irq
) < 0 && errno
== EINVAL
)
250 offset
= 0x0600; /* We don't understand the new ioctls */
255 if (cmds
->op
== LPGETSTATUS
) {
257 retval
= ioctl(fd
, LPGETSTATUS
- offset
, &status
);
259 perror("LPGETSTATUS error");
261 if (status
== 0xdeadbeef) /* a few 1.1.7x kernels will do this */
263 printf(_("%s status is %d"), filename
, status
);
264 if (!(status
& LP_PBUSY
)) printf(_(", busy"));
265 if (!(status
& LP_PACK
)) printf(_(", ready"));
266 if ((status
& LP_POUTPA
)) printf(_(", out of paper"));
267 if ((status
& LP_PSELECD
)) printf(_(", on-line"));
268 if (!(status
& LP_PERRORP
)) printf(_(", error"));
272 #endif /* LPGETSTATUS */
273 if (ioctl(fd
, cmds
->op
- offset
, cmds
->val
) < 0) {
274 perror("tunelp: ioctl");
283 retval
= ioctl(fd
, LPGETIRQ
- offset
, &irq
);
285 perror(_("LPGETIRQ error"));
288 if (irq
== 0xdeadbeef) /* up to 1.1.77 will do this */
291 printf(_("%s using IRQ %d\n"), filename
, irq
);
293 printf(_("%s using polling\n"), filename
);