HAMMER - Stabilize and refactor volume removal
[dragonfly.git] / usr.sbin / sgsc / sgsc.c
blobb53678860e2d12993630559fca0247ed999434d4
1 /* sgsc(1) - utility for the `gsc' scanner device driver
4 * Copyright (c) 1995 Gunther Schadow. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Gunther Schadow.
17 * 4. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 * $FreeBSD: src/usr.sbin/sgsc/sgsc.c,v 1.5 1999/08/28 01:19:57 peter Exp $
32 * $DragonFly: src/usr.sbin/sgsc/sgsc.c,v 1.3 2005/12/05 02:40:28 swildner Exp $
35 #include <err.h>
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <unistd.h>
39 #include <sys/file.h>
40 #include <sys/ioctl.h>
41 #include <machine/gsc.h>
43 #ifndef DEFAULT_FILE
44 #define DEFAULT_FILE "/dev/gsc0"
45 #endif
46 #ifdef FAIL
47 #undef FAIL
48 #endif
49 #define FAIL -1
51 static void
52 usage(void)
54 fprintf(stderr, "%s\n%s\n",
55 "usage: sgsc [-sq] [-f file] [-r dpi] [-w width] [-h height]",
56 " [-b len] [-t time]");
57 exit(1);
60 int
61 main(int argc, char **argv)
63 char c;
64 int fd;
66 char *file = DEFAULT_FILE;
68 int show_dpi = 0;
69 int show_width = 0;
70 int show_height = 0;
71 int show_blen = 0;
72 int show_btime = 0;
73 int show_all = 1;
75 int set_blen = 0;
76 int set_dpi = 0;
77 int set_width = 0;
78 int set_height = 0;
79 int set_btime = 0;
80 int set_switch = 0;
82 if (argc == 0) usage();
84 while( (c = getopt(argc, argv, "sqf:b:r:w:h:t:")) != FAIL)
86 switch(c) {
87 case 'f': file = optarg; break;
88 case 'r': set_dpi = atoi(optarg); break;
89 case 'w': set_width = atoi(optarg); break;
90 case 'h': set_height = atoi(optarg); break;
91 case 'b': set_blen = atoi(optarg); break;
92 case 't': set_btime = atoi(optarg); break;
93 case 's': set_switch = 1; break;
94 case 'q': show_all = 0; break;
95 default: usage();
99 fd = open(file, O_RDONLY);
100 if ( fd == FAIL )
101 err(1, "%s", file);
103 if (set_switch != 0)
105 if(ioctl(fd, GSC_SRESSW) == FAIL)
106 err(1, "GSC_SRESSW");
109 if (set_dpi != 0)
111 if(ioctl(fd, GSC_SRES, &set_dpi) == FAIL)
112 err(1, "GSC_SRES");
115 if (set_width != 0)
117 if(ioctl(fd, GSC_SWIDTH, &set_width) == FAIL)
118 err(1, "GSC_SWIDTH");
121 if (set_height != 0)
123 if(ioctl(fd, GSC_SHEIGHT, &set_height) == FAIL)
124 err(1, "GSC_SHEIGHT");
127 if (set_blen != 0)
129 if(ioctl(fd, GSC_SBLEN, &set_blen) == FAIL)
130 err(1, "GSC_SBLEN");
133 if (set_btime != 0)
135 if(ioctl(fd, GSC_SBTIME, &set_btime) == FAIL)
136 err(1, "GSC_SBTIME");
139 if (show_all != 0)
141 if(ioctl(fd, GSC_GRES, &show_dpi) == FAIL)
142 err(1, "GSC_GRES");
143 if(ioctl(fd, GSC_GWIDTH, &show_width) == FAIL)
144 err(1, "GSC_GWIDTH");
145 if(ioctl(fd, GSC_GHEIGHT, &show_height) == FAIL)
146 err(1, "GSC_GHEIGHT");
147 if(ioctl(fd, GSC_GBLEN, &show_blen) == FAIL)
148 err(1, "GSC_GBLEN");
149 if(ioctl(fd, GSC_GBTIME, &show_btime) == FAIL)
150 err(1, "GSC_GBTIME");
152 printf("%s:\n", file);
153 printf("resolution\t %d dpi\n", show_dpi);
154 printf("width\t\t %d\n", show_width);
155 printf("height\t\t %d\n",show_height);
156 printf("buffer length\t %d\n", show_blen);
157 printf("buffer timeout\t %d\n", show_btime);
160 return 0;