2 * sasc(1) - utility for the `asc' scanner device driver
4 * Copyright (c) 1995 Gunther Schadow. All rights reserved.
5 * Copyright (c) 2004 Liam J. Foy. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Gunther Schadow.
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 * $FreeBSD: src/usr.bin/sasc/sasc.c,v 1.7.2.1 2000/06/30 09:47:52 ps Exp $
33 * $DragonFly: src/usr.bin/sasc/sasc.c,v 1.6 2007/01/21 10:40:39 swildner Exp $
38 #include <sys/ioctl.h>
39 #include <sys/types.h>
41 #include <machine/asc_ioctl.h>
42 #include <machine/limits.h>
50 #define DEFAULT_FILE "/dev/asc0"
52 static int getnum(const char *);
53 static int asc_get(int, u_long
);
54 static void asc_set(int, u_long
, int, const char *);
55 static void usage(void);
61 "usage: sasc [-sq] [-f file] [-r dpi] [-w width] [-h height]"
62 "[-b len] [-t time]\n");
66 /* Check given numerical arguments */
68 getnum(const char *str
)
74 val
= strtol(str
, &ep
, 10);
76 err(1, "strtol failed: %s", str
);
78 if (str
== ep
|| *ep
!= '\0')
79 errx(1, "invalid value: %s", str
);
81 if (val
> INT_MAX
|| val
< INT_MIN
) {
83 errc(1, errno
, "getnum failed:");
90 asc_set(int fd
, u_long asc_setting
, int asc_value
, const char *asc_type
)
92 if (ioctl(fd
, asc_setting
, &asc_value
) < 0)
93 err(1, "ioctl failed setting %s(%d)", asc_type
, asc_value
);
95 printf("Successfully set\n");
99 asc_get(int fd
, u_long asc_setting
)
103 if (ioctl(fd
, asc_setting
, &asc_value
) < 0)
104 err(1, "ioctl failed");
110 main(int argc
, char **argv
)
112 const char *file
= DEFAULT_FILE
;
114 int show_dpi
, show_width
, show_height
;
115 int show_blen
, show_btime
, show_all
;
116 int set_blen
, set_dpi
, set_width
;
117 int set_height
, set_btime
, set_switch
;
119 show_dpi
= show_width
= show_height
= 0;
120 show_blen
= show_btime
= show_all
= 0;
122 set_blen
= set_dpi
= set_width
= 0;
123 set_height
= set_btime
= set_switch
= 0;
125 while ((c
= getopt(argc
, argv
, "sqf:b:r:w:h:t:")) != -1) {
131 set_dpi
= getnum(optarg
);
134 set_width
= getnum(optarg
);
137 set_height
= getnum(optarg
);
140 set_blen
= getnum(optarg
);
143 set_btime
= getnum(optarg
);
159 if ((fd
= open(file
, O_RDWR
)) == -1)
160 err(1, "Unable to open: %s", file
);
163 if (ioctl(fd
, ASC_SRESSW
) < 0)
164 err(1, "ioctl: ASC_SRESSW failed");
168 asc_set(fd
, ASC_SRES
, set_dpi
, "ASC_SRES");
171 asc_set(fd
, ASC_SWIDTH
, set_width
, "ASC_SWIDTH");
174 asc_set(fd
, ASC_SHEIGHT
, set_height
, "ASC_SHEIGHT");
177 asc_set(fd
, ASC_SBLEN
, set_blen
, "ASC_SBLEN");
180 asc_set(fd
, ASC_SBTIME
, set_btime
, "ASC_SBTIME");
183 show_dpi
= asc_get(fd
, ASC_GRES
);
184 show_width
= asc_get(fd
, ASC_GWIDTH
);
185 show_height
= asc_get(fd
, ASC_GHEIGHT
);
186 show_blen
= asc_get(fd
, ASC_GBLEN
);
187 show_btime
= asc_get(fd
, ASC_GBTIME
);
189 printf("Device: %s\n", file
);
190 printf("Resolution: %d dpi\n", show_dpi
);
191 printf("Width: %d\n", show_width
);
192 printf("Height: %d\n", show_height
);
193 printf("Buffer length: %d\n", show_blen
);
194 printf("Buffer timeout: %d\n", show_btime
);