2 * Copyright (C) 1992-1997 Michael K. Johnson, johnsonm@redhat.com
4 * This file is licensed under the terms of the GNU General Public
5 * License, version 2, or any later version. See file COPYING for
6 * information on distribution conditions.
10 * This command is deprecated. The utility is in maintenance mode,
11 * meaning we keep them in source tree for backward compatibility
12 * only. Do not waste time making this command better, unless the
13 * fix is about security or other very critical issue.
15 * See Documentation/deprecated.txt for more information.
20 * Revision 1.9 1998/06/08 19:37:11 janl
21 * Thus compiles tunelp with 2.1.103 kernels
23 * Revision 1.8 1997/07/06 00:14:06 aebr
24 * Fixes to silence -Wall.
26 * Revision 1.7 1997/06/20 16:10:38 janl
27 * tunelp refreshed from authors archive.
29 * Revision 1.9 1997/06/20 12:56:43 johnsonm
30 * Finished fixing license terms.
32 * Revision 1.8 1997/06/20 12:34:59 johnsonm
33 * Fixed copyright and license.
35 * Revision 1.7 1995/03/29 11:16:23 johnsonm
38 * Revision 1.6 1995/03/29 11:12:15 johnsonm
39 * Added third argument to ioctl needed with new kernels
41 * Revision 1.5 1995/01/13 10:33:43 johnsonm
42 * Chris's changes for new ioctl numbers and backwards compatibility
43 * and the reset ioctl.
45 * Revision 1.4 1995/01/03 17:42:14 johnsonm
46 * -s isn't supposed to take an argument; removed : after s in getopt...
48 * Revision 1.3 1995/01/03 07:36:49 johnsonm
51 * Revision 1.2 1995/01/03 07:33:44 johnsonm
52 * revisions for lp driver updates in Linux 1.1.76
54 * 1999-02-22 Arkadiusz MiĆkiewicz <misiek@pld.ORG.PL>
55 * - added Native Language Support
57 * 1999-05-07 Merged LPTRUSTIRQ patch by Andrea Arcangeli (1998/11/29), aeb
67 #include <sys/ioctl.h>
69 #include <sys/types.h>
75 #include "closestream.h"
78 #define EXIT_LP_MALLOC 2
79 #define EXIT_LP_BADVAL 3
80 #define EXIT_LP_IO_ERR 4
82 #define XALLOC_EXIT_CODE EXIT_LP_MALLOC
91 static void __attribute__((__noreturn__
)) usage(void)
94 fputs(USAGE_HEADER
, out
);
95 fprintf(out
, _(" %s [options] <device>\n"), program_invocation_short_name
);
97 fputs(USAGE_SEPARATOR
, out
);
98 fputs(_("Set various parameters for the line printer.\n"), out
);
100 fputs(USAGE_OPTIONS
, out
);
101 fputs(_(" -i, --irq <num> specify parallel port irq\n"), out
);
102 fputs(_(" -t, --time <ms> driver wait time in milliseconds\n"), out
);
103 fputs(_(" -c, --chars <num> number of output characters before sleep\n"), out
);
104 fputs(_(" -w, --wait <us> strobe wait in micro seconds\n"), out
);
105 /* TRANSLATORS: do not translate <on|off> arguments. The
106 argument reader does not recognize locale, unless `on' is
107 exactly that very same string. */
108 fputs(_(" -a, --abort <on|off> abort on error\n"), out
);
109 fputs(_(" -o, --check-status <on|off> check printer status before printing\n"), out
);
110 fputs(_(" -C, --careful <on|off> extra checking to status check\n"), out
);
111 fputs(_(" -s, --status query printer status\n"), out
);
112 fputs(_(" -r, --reset reset the port\n"), out
);
113 fputs(_(" -q, --print-irq <on|off> display current irq setting\n"), out
);
114 fputs(USAGE_SEPARATOR
, out
);
115 printf(USAGE_HELP_OPTIONS(30));
116 printf(USAGE_MAN_TAIL("tunelp(8)"));
121 int main(int argc
, char **argv
)
123 int c
, fd
, irq
, status
, show_irq
, offset
= 0, retval
;
126 struct command
*cmds
, *cmdst
;
127 static const struct option longopts
[] = {
128 {"irq", required_argument
, NULL
, 'i'},
129 {"time", required_argument
, NULL
, 't'},
130 {"chars", required_argument
, NULL
, 'c'},
131 {"wait", required_argument
, NULL
, 'w'},
132 {"abort", required_argument
, NULL
, 'a'},
133 {"check-status", required_argument
, NULL
, 'o'},
134 {"careful", required_argument
, NULL
, 'C'},
135 {"status", no_argument
, NULL
, 's'},
136 {"trust-irq", required_argument
, NULL
, 'T'},
137 {"reset", no_argument
, NULL
, 'r'},
138 {"print-irq", required_argument
, NULL
, 'q'},
139 {"version", no_argument
, NULL
, 'V'},
140 {"help", no_argument
, NULL
, 'h'},
144 setlocale(LC_ALL
, "");
145 bindtextdomain(PACKAGE
, LOCALEDIR
);
147 atexit(close_stdout
);
149 strutils_set_exitcode(EXIT_LP_BADVAL
);
152 warnx(_("not enough arguments"));
153 errtryhelp(EXIT_FAILURE
);
156 cmdst
= cmds
= xmalloc(sizeof(struct command
));
160 while ((c
= getopt_long(argc
, argv
, "t:c:w:a:i:ho:C:sq:rT:vV", longopts
, NULL
)) != -1) {
167 cmds
->val
= strtol_or_err(optarg
, _("argument error"));
168 cmds
->next
= xmalloc(sizeof(struct command
));
174 cmds
->val
= strtol_or_err(optarg
, _("argument error"));
175 cmds
->next
= xmalloc(sizeof(struct command
));
181 cmds
->val
= strtol_or_err(optarg
, _("argument error"));
182 cmds
->next
= xmalloc(sizeof(struct command
));
188 cmds
->val
= strtol_or_err(optarg
, _("argument error"));
189 cmds
->next
= xmalloc(sizeof(struct command
));
195 cmds
->val
= parse_switch(optarg
, _("argument error"), "on", "off", NULL
);
196 cmds
->next
= xmalloc(sizeof(struct command
));
201 show_irq
= parse_switch(optarg
, _("argument error"), "on", "off", NULL
);
204 cmds
->op
= LPABORTOPEN
;
205 cmds
->val
= parse_switch(optarg
, _("argument error"), "on", "off", NULL
);
206 cmds
->next
= xmalloc(sizeof(struct command
));
211 cmds
->op
= LPCAREFUL
;
212 cmds
->val
= parse_switch(optarg
, _("argument error"), "on", "off", NULL
);
213 cmds
->next
= xmalloc(sizeof(struct command
));
219 cmds
->op
= LPGETSTATUS
;
221 cmds
->next
= xmalloc(sizeof(struct command
));
228 cmds
->next
= xmalloc(sizeof(struct command
));
234 printf(UTIL_LINUX_VERSION
);
237 errtryhelp(EXIT_FAILURE
);
241 if (optind
!= argc
- 1) {
242 warnx(_("no device specified"));
243 errtryhelp(EXIT_FAILURE
);
246 filename
= xstrdup(argv
[optind
]);
247 fd
= open(filename
, O_WRONLY
| O_NONBLOCK
, 0);
248 /* Need to open O_NONBLOCK in case ABORTOPEN is already set
249 * and printer is off or off-line or in an error condition.
250 * Otherwise we would abort...
253 err(EXIT_FAILURE
, "%s", filename
);
255 if (fstat(fd
, &statbuf
))
256 err(EXIT_FAILURE
, "%s: stat() failed", filename
);
258 if (!S_ISCHR(statbuf
.st_mode
)) {
259 warnx(_("%s not an lp device"), filename
);
260 errtryhelp(EXIT_FAILURE
);
262 /* Allow for binaries compiled under a new kernel to work on
263 * the old ones The irq argument to ioctl isn't touched by
264 * the old kernels, but we don't want to cause the kernel to
265 * complain if we are using a new kernel
267 if (LPGETIRQ
>= 0x0600 && ioctl(fd
, LPGETIRQ
, &irq
) < 0
269 /* We don't understand the new ioctls */
274 if (cmds
->op
== LPGETSTATUS
) {
276 retval
= ioctl(fd
, LPGETSTATUS
- offset
, &status
);
278 warnx(_("LPGETSTATUS error"));
280 if (status
== (int)0xdeadbeef)
281 /* a few 1.1.7x kernels will do this */
283 printf(_("%s status is %d"), filename
, status
);
284 if (!(status
& LP_PBUSY
))
286 if (!(status
& LP_PACK
))
287 printf(_(", ready"));
288 if ((status
& LP_POUTPA
))
289 printf(_(", out of paper"));
290 if ((status
& LP_PSELECD
))
291 printf(_(", on-line"));
292 if (!(status
& LP_PERRORP
))
293 printf(_(", error"));
297 if (ioctl(fd
, cmds
->op
- offset
, cmds
->val
) < 0)
298 warn(_("ioctl failed"));
306 retval
= ioctl(fd
, LPGETIRQ
- offset
, &irq
);
308 err(EXIT_LP_IO_ERR
, _("LPGETIRQ error"));
309 if (irq
== (int)0xdeadbeef)
310 /* up to 1.1.77 will do this */
313 printf(_("%s using IRQ %d\n"), filename
, irq
);
315 printf(_("%s using polling\n"), filename
);