Initial import from FreeBSD RELENG_4:
[dragonfly.git] / usr.bin / sasc / sasc.c
1 /* sasc(1) - utility for the `asc' scanner device driver
2  *
3  *
4  * Copyright (c) 1995 Gunther Schadow.  All rights reserved.
5  *
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.
19  *
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.
30  */
31
32 #ifndef lint
33 static const char rcsid[] =
34   "$FreeBSD: src/usr.bin/sasc/sasc.c,v 1.7.2.1 2000/06/30 09:47:52 ps Exp $";
35 #endif /* not lint */
36
37 #include <err.h>
38 #include <stdlib.h>
39 #include <stdio.h>
40 #include <unistd.h>
41 #include <sys/file.h>
42 #include <sys/ioctl.h>
43 #include <machine/asc_ioctl.h>
44
45 #ifndef DEFAULT_FILE
46 #define DEFAULT_FILE "/dev/asc0"
47 #endif
48 #ifdef FAIL
49 #undef FAIL
50 #endif
51 #define FAIL -1
52
53 static void usage __P((void));
54
55 static void
56 usage()
57 {
58         fprintf(stderr,
59 "usage: sasc [-sq] [-f file] [-r dpi] [-w width] [-h height] \
60 [-b len] [-t time]\n");
61         exit(1);
62 }
63
64 int
65 main(int argc, char **argv)
66 {
67   char c;
68   int fd;
69
70   char *file = DEFAULT_FILE;
71   
72   int show_dpi     = 0;
73   int show_width   = 0;
74   int show_height  = 0;
75   int show_blen    = 0;
76   int show_btime   = 0;
77   int show_all     = 1;
78
79   int set_blen     = 0;
80   int set_dpi      = 0;
81   int set_width    = 0;
82   int set_height   = 0;
83   int set_btime    = 0;
84   int set_switch   = 0;
85
86   if (argc == 0) usage();
87
88   while( (c = getopt(argc, argv, "sqf:b:r:w:h:t:")) != -1)
89     {
90       switch(c) {
91       case 'f': file = optarg; break;
92       case 'r': set_dpi = atoi(optarg); break;
93       case 'w': set_width = atoi(optarg); break;
94       case 'h': set_height = atoi(optarg); break;
95       case 'b': set_blen = atoi(optarg); break;
96       case 't': set_btime = atoi(optarg); break;
97       case 's': set_switch = 1; break;
98       case 'q': show_all = 0; break;
99       default: usage();
100       }
101     }
102
103   fd = open(file, O_RDONLY);
104   if ( fd == FAIL )
105     err(1, "%s", file);
106
107   if (set_switch != 0)
108     {
109       if(ioctl(fd, ASC_SRESSW) == FAIL)
110                 err(1, "ASC_SRESSW");
111     }
112
113   if (set_dpi != 0)
114     {
115       if(ioctl(fd, ASC_SRES, &set_dpi) == FAIL)
116                 err(1, "ASC_SRES");
117     }
118
119   if (set_width != 0)
120     {
121       if(ioctl(fd, ASC_SWIDTH, &set_width) == FAIL)
122                 err(1, "ASC_SWIDTH");
123     }
124
125   if (set_height != 0)
126     {
127       if(ioctl(fd, ASC_SHEIGHT, &set_height) == FAIL)
128                 err(1, "ASC_SHEIGHT");
129     }
130
131   if (set_blen != 0)
132     {
133       if(ioctl(fd, ASC_SBLEN, &set_blen) == FAIL)
134                 err(1, "ASC_SBLEN");
135     }
136
137   if (set_btime != 0)
138     {
139       if(ioctl(fd, ASC_SBTIME, &set_btime) == FAIL)
140                 err(1, "ASC_SBTIME");
141     }
142
143   if (show_all != 0)
144     {
145       if(ioctl(fd, ASC_GRES,  &show_dpi) == FAIL)
146                 err(1, "ASC_GRES");
147       if(ioctl(fd, ASC_GWIDTH,  &show_width) == FAIL)
148                 err(1, "ASC_GWIDTH");
149       if(ioctl(fd, ASC_GHEIGHT,  &show_height) == FAIL)
150                 err(1, "ASC_GHEIGHT");
151       if(ioctl(fd, ASC_GBLEN, &show_blen) == FAIL)
152                 err(1, "ASC_GBLEN");
153       if(ioctl(fd, ASC_GBTIME, &show_btime) == FAIL)
154                 err(1, "ASC_GBTIME");
155
156       printf("%s:\n", file);
157       printf("resolution\t %d dpi\n", show_dpi);
158       printf("width\t\t %d\n", show_width);
159       printf("height\t\t %d\n",show_height);
160       printf("buffer length\t %d\n", show_blen);
161       printf("buffer timeout\t %d\n", show_btime);
162     }
163
164   return 0;
165 }