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