summaryrefslogtreecommitdiffstats
path: root/usr.sbin/lptcontrol/lptcontrol.c
diff options
context:
space:
mode:
authorcsgr <csgr@FreeBSD.org>1994-09-03 22:47:08 +0000
committercsgr <csgr@FreeBSD.org>1994-09-03 22:47:08 +0000
commit7b6e72a847a7d44c2c26046d7b7b45ffb24d6bac (patch)
treefae137773c8b7b37ab895b0c2108c844082d5eb7 /usr.sbin/lptcontrol/lptcontrol.c
parent010d228ad6975af67848079ecbeca590d3ac7ed1 (diff)
downloadFreeBSD-src-7b6e72a847a7d44c2c26046d7b7b45ffb24d6bac.zip
FreeBSD-src-7b6e72a847a7d44c2c26046d7b7b45ffb24d6bac.tar.gz
Make it possible to run lptcontrol on a printer port which does not
actually have a printer connected or online: - MAKEDEV: remove all signs of lpa add lpctl? devices (minor # = unit + 128) - usr.sbin/Makefile add lptcontrol - sys/i386/isa/lpt.c implement the LP_BYPASS flag: when a unit is opened with this flag set, the printer is not primed, and no check is made to see that the printer is online. This can only be used to pass ioctls. (giving us /dev/lpctl?) - lptcontrol.c use /dev/lpctl? (LP_BYPASS) -f flag removed, -u flag added - lptcontrol.8 document changes in lptcontrol rewrite using mandoc macros Submitted by: Geoff.
Diffstat (limited to 'usr.sbin/lptcontrol/lptcontrol.c')
-rw-r--r--usr.sbin/lptcontrol/lptcontrol.c54
1 files changed, 37 insertions, 17 deletions
diff --git a/usr.sbin/lptcontrol/lptcontrol.c b/usr.sbin/lptcontrol/lptcontrol.c
index bcb3ad3..cbe0410 100644
--- a/usr.sbin/lptcontrol/lptcontrol.c
+++ b/usr.sbin/lptcontrol/lptcontrol.c
@@ -27,30 +27,35 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $Id: lptcontrol.c,v 1.2 1994/04/08 22:23:39 csgr Exp $
+ * $Id: lptcontrol.c,v 1.1.1.1 1994/09/03 13:10:09 csgr Exp $
*/
-#include <sys/types.h>
-#include <sys/file.h>
-#include <sys/ioctl.h>
-#include <machine/lpt.h>
-#include <stdlib.h>
-#include <unistd.h>
+#include <ctype.h>
+#include <limits.h>
+#include <paths.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
+
+#include <machine/lpt.h>
#include <sys/errno.h>
+#include <sys/file.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
-#define DEFAULT_LPT "/dev/lpt0"
+#define PATH_LPCTL _PATH_DEV "lpctl"
+#define DEFAULT_UNIT "0"
#define IRQ_INVALID -1
#define DO_POLL 0
#define USE_IRQ 1
-static char default_printer[] = DEFAULT_LPT;
-
static void usage(const char * progname)
{
- fprintf(stderr, "usage: %s -i | -p [-f <file name>]\n", progname);
+ fprintf(stderr, "usage: %s -i | -p [-u <unit no.>]\n", progname);
+ fprintf(stderr, "\tUnit no. is a value in the range 0 to 3\n");
+ fprintf(stderr, "\tThe default unit no is 0 (ie. /dev/lpt0)\n");
exit(1);
}
@@ -69,23 +74,38 @@ static void set_interrupt_status(int irq_status, const char * file)
close(fd);
}
+static char * dev_file(char unit_no)
+{
+ static char devname[_POSIX_PATH_MAX+1];
+ int len;
+
+ strncpy(devname, PATH_LPCTL, _POSIX_PATH_MAX);
+ devname[len = strlen(devname)] = unit_no;
+ devname[++len] = '\0';
+
+ return(devname);
+}
int main (int argc, char * argv[])
{
int opt;
- int irq_status = -1;
- char * file = default_printer;
+ int irq_status = IRQ_INVALID;
+ char * unit = DEFAULT_UNIT;
- while((opt = getopt(argc, argv, "pif:")) != -1)
+ while((opt = getopt(argc, argv, "ipu:")) != -1)
switch(opt) {
case 'i': irq_status = USE_IRQ; break;
case 'p': irq_status = DO_POLL; break;
- case 'f': file = optarg; break;
+ case 'u': unit = optarg;
+ if(!isdigit(*unit))
+ usage(argv[0]);
+ break;
default : usage(argv[0]);
}
- if(irq_status == IRQ_INVALID) usage(argv[0]);
+ if(irq_status == IRQ_INVALID)
+ usage(argv[0]);
- set_interrupt_status(irq_status, file);
+ set_interrupt_status(irq_status, dev_file(*unit));
exit(0);
}
OpenPOWER on IntegriCloud