Thu Aug 25 17:00:55 2011 UTC ()
fix non-literal format strings


(christos)
diff -r1.12 -r1.13 src/sys/arch/x68k/usr.bin/bellctrl/bellctrl.c

cvs diff -r1.12 -r1.13 src/sys/arch/x68k/usr.bin/bellctrl/bellctrl.c (expand / switch to unified diff)

--- src/sys/arch/x68k/usr.bin/bellctrl/bellctrl.c 2011/05/19 21:26:39 1.12
+++ src/sys/arch/x68k/usr.bin/bellctrl/bellctrl.c 2011/08/25 17:00:55 1.13
@@ -1,71 +1,69 @@ @@ -1,71 +1,69 @@
1/* $NetBSD: bellctrl.c,v 1.12 2011/05/19 21:26:39 tsutsui Exp $ */ 1/* $NetBSD: bellctrl.c,v 1.13 2011/08/25 17:00:55 christos Exp $ */
2 2
3/* 3/*
4 * bellctrl - OPM bell controller (for NetBSD/X680x0) 4 * bellctrl - OPM bell controller (for NetBSD/X680x0)
5 * Copyright (c)1995 ussy. 5 * Copyright (c)1995 ussy.
6 */ 6 */
7 7
8#include <sys/cdefs.h> 8#include <sys/cdefs.h>
9__RCSID("$NetBSD: bellctrl.c,v 1.12 2011/05/19 21:26:39 tsutsui Exp $"); 9__RCSID("$NetBSD: bellctrl.c,v 1.13 2011/08/25 17:00:55 christos Exp $");
10 10
11#include <err.h> 11#include <err.h>
12#include <stdio.h> 12#include <stdio.h>
13#include <stdlib.h> 13#include <stdlib.h>
14#include <unistd.h> 14#include <unistd.h>
15#include <ctype.h> 15#include <ctype.h>
16#include <string.h> 16#include <string.h>
17#include <sys/file.h> 17#include <sys/file.h>
18#include <sys/ioctl.h> 18#include <sys/ioctl.h>
19#include <machine/opmbellio.h> 19#include <machine/opmbellio.h>
20 20
21#define DEFAULT -1 21#define DEFAULT -1
22 22
23#define nextarg(i, argv) \ 23#define nextarg(i, argv) \
24 argv[i]; \ 24 argv[i]; \
25 if (i >= argc) \ 25 if (i >= argc) \
26 break; \ 26 break; \
27 27
28int bell_setting; 28static int bell_setting;
29char *progName; 29static struct opm_voice voice;
30struct opm_voice voice; 
31 30
32static struct opm_voice bell_voice = DEFAULT_BELL_VOICE; 31static struct opm_voice bell_voice = DEFAULT_BELL_VOICE;
33 32
34static struct bell_info values = { 33static struct bell_info values = {
35 DEFAULT, DEFAULT, DEFAULT 34 DEFAULT, DEFAULT, DEFAULT
36}; 35};
37 36
38/* function prototype */ 37/* function prototype */
39int is_number(const char *, int); 38static int is_number(const char *, int);
40void set_bell_vol(int); 39static void set_bell_vol(int);
41void set_bell_pitch(int); 40static void set_bell_pitch(int);
42void set_bell_dur(int); 41static void set_bell_dur(int);
43void set_voice_param(const char *, int); 42static void set_voice_param(const char *, int);
44void set_bell_param(void); 43static void set_bell_param(void);
45int usage(const char *, const char *); 44static void usage(void) __dead;
46 45
47int 46int
48main(int argc, char **argv) 47main(int argc, char **argv)
49{ 48{
50 const char *arg; 49 const char *arg;
51 int percent; 50 int percent;
52 int i; 51 int i;
53 52
54 progName = argv[0]; 
55 bell_setting = 0; 53 bell_setting = 0;
56 54
57 if (argc < 2) 55 if (argc < 2)
58 usage(NULL, NULL); 56 usage();
59 57
60 for (i = 1; i < argc; ) { 58 for (i = 1; i < argc; ) {
61 arg = argv[i++]; 59 arg = argv[i++];
62 if (strcmp(arg, "-b") == 0) { 60 if (strcmp(arg, "-b") == 0) {
63 /* turn off bell */ 61 /* turn off bell */
64 set_bell_vol(0); 62 set_bell_vol(0);
65 } else if (strcmp(arg, "b") == 0) { 63 } else if (strcmp(arg, "b") == 0) {
66 /* set bell to default */ 64 /* set bell to default */
67 percent = DEFAULT; 65 percent = DEFAULT;
68 66
69 if (i >= argc) { 67 if (i >= argc) {
70 /* set bell to default */ 68 /* set bell to default */
71 set_bell_vol(percent); 69 set_bell_vol(percent);
@@ -127,135 +125,132 @@ main(int argc, char **argv) @@ -127,135 +125,132 @@ main(int argc, char **argv)
127 * set voice parameter 125 * set voice parameter
128 */ 126 */
129 if (i >= argc) { 127 if (i >= argc) {
130 arg = "default"; 128 arg = "default";
131 } else { 129 } else {
132 arg = nextarg(i, argv); 130 arg = nextarg(i, argv);
133 } 131 }
134 set_voice_param(arg, 1); 132 set_voice_param(arg, 1);
135 i++; 133 i++;
136 } else if (strcmp(arg, "-v") == 0) { 134 } else if (strcmp(arg, "-v") == 0) {
137 /* 135 /*
138 * set voice parameter 136 * set voice parameter
139 */ 137 */
140 if (i >= argc) 138 if (i >= argc) {
141 usage("missing -v argument", NULL); 139 warnx("Missing -v argument");
 140 usage();
 141 }
142 arg = nextarg(i, argv); 142 arg = nextarg(i, argv);
143 set_voice_param(arg, 0); 143 set_voice_param(arg, 0);
144 i++; 144 i++;
145 } else { 145 } else {
146 usage("unknown option %s", arg); 146 warnx("Unknown option %s", arg);
 147 usage();
147 } 148 }
148 } 149 }
149 150
150 if (bell_setting) 151 if (bell_setting)
151 set_bell_param(); 152 set_bell_param();
152 153
153 exit(0); 154 exit(0);
154} 155}
155 156
156int 157static int
157is_number(const char *arg, int maximum) 158is_number(const char *arg, int maximum)
158{ 159{
159 const char *p; 160 const char *p;
160 161
161 if (arg[0] == '-' && arg[1] == '1' && arg[2] == '\0') 162 if (arg[0] == '-' && arg[1] == '1' && arg[2] == '\0')
162 return 1; 163 return 1;
163 for (p = arg; isdigit((unsigned char)*p); p++) 164 for (p = arg; isdigit((unsigned char)*p); p++)
164 ; 165 ;
165 if (*p || atoi(arg) > maximum) 166 if (*p || atoi(arg) > maximum)
166 return 0; 167 return 0;
167 168
168 return 1; 169 return 1;
169} 170}
170 171
171void 172static void
172set_bell_vol(int percent) 173set_bell_vol(int percent)
173{ 174{
174 values.volume = percent; 175 values.volume = percent;
175 bell_setting++; 176 bell_setting++;
176} 177}
177 178
178void 179static void
179set_bell_pitch(int pitch) 180set_bell_pitch(int pitch)
180{ 181{
181 values.pitch = pitch; 182 values.pitch = pitch;
182 bell_setting++; 183 bell_setting++;
183} 184}
184 185
185void 186static void
186set_bell_dur(int duration) 187set_bell_dur(int duration)
187{ 188{
188 values.msec = duration; 189 values.msec = duration;
189 bell_setting++; 190 bell_setting++;
190} 191}
191 192
192void 193static void
193set_voice_param(const char *path, int flag) 194set_voice_param(const char *path, int flag)
194{ 195{
195 int fd; 196 int fd;
196 197
197 if (flag) { 198 if (flag) {
198 memcpy(&voice, &bell_voice, sizeof(bell_voice)); 199 memcpy(&voice, &bell_voice, sizeof(bell_voice));
199 } else { 200 } else {
200 if ((fd = open(path, 0)) >= 0) { 201 if ((fd = open(path, 0)) >= 0) {
201 if (read(fd, &voice, sizeof(voice)) != sizeof(voice)) 202 if (read(fd, &voice, sizeof(voice)) != sizeof(voice))
202 err(1, "cannot read voice parameter"); 203 err(1, "cannot read voice parameter");
203 close(fd); 204 close(fd);
204 } else { 205 } else {
205 err(1, "cannot open voice parameter"); 206 err(1, "cannot open voice parameter");
206 } 207 }
207 } 208 }
208 209
209 if ((fd = open("/dev/bell", O_RDWR)) < 0) 210 if ((fd = open("/dev/bell", O_RDWR)) < 0)
210 err(1, "cannot open /dev/bell"); 211 err(1, "cannot open /dev/bell");
211 if (ioctl(fd, BELLIOCSVOICE, &voice)) 212 if (ioctl(fd, BELLIOCSVOICE, &voice))
212 err(1, "ioctl BELLIOCSVOICE failed"); 213 err(1, "ioctl BELLIOCSVOICE failed");
213 214
214 close(fd); 215 close(fd);
215} 216}
216 217
217void 218static void
218set_bell_param(void) 219set_bell_param(void)
219{ 220{
220 int fd; 221 int fd;
221 struct bell_info param; 222 struct bell_info param;
222 223
223 if ((fd = open("/dev/bell", O_RDWR)) < 0) 224 if ((fd = open("/dev/bell", O_RDWR)) < 0)
224 err(1, "cannot open /dev/bell"); 225 err(1, "cannot open /dev/bell");
225 if (ioctl(fd, BELLIOCGPARAM, &param)) 226 if (ioctl(fd, BELLIOCGPARAM, &param))
226 err(1, "ioctl BELLIOCGPARAM failed"); 227 err(1, "ioctl BELLIOCGPARAM failed");
227 228
228 if (values.volume == DEFAULT) 229 if (values.volume == DEFAULT)
229 values.volume = param.volume; 230 values.volume = param.volume;
230 if (values.pitch == DEFAULT) 231 if (values.pitch == DEFAULT)
231 values.pitch = param.pitch; 232 values.pitch = param.pitch;
232 if (values.msec == DEFAULT) 233 if (values.msec == DEFAULT)
233 values.msec = param.msec; 234 values.msec = param.msec;
234 235
235 if (ioctl(fd, BELLIOCSPARAM, &values)) 236 if (ioctl(fd, BELLIOCSPARAM, &values))
236 err(1, "ioctl BELLIOCSPARAM failed"); 237 err(1, "ioctl BELLIOCSPARAM failed");
237 238
238 close(fd); 239 close(fd);
239} 240}
240 241
241int 242static void
242usage(const char *fmt, const char *arg) 243usage(void)
243{ 244{
244 if (fmt) { 245 fprintf(stderr, "Usage: %s option ...\n", getprogname());
245 fprintf(stderr, "%s: ", progName); 
246 fprintf(stderr, fmt, arg); 
247 fprintf(stderr, "\n\n"); 
248 } 
249 
250 fprintf(stderr, "usage: %s option ...\n", progName); 
251 fprintf(stderr, " To turn bell off:\n"); 246 fprintf(stderr, " To turn bell off:\n");
252 fprintf(stderr, "\t-b b off" 247 fprintf(stderr, "\t-b b off"
253 " b 0\n"); 248 " b 0\n");
254 fprintf(stderr, " To set bell volume, pitch and duration:\n"); 249 fprintf(stderr, " To set bell volume, pitch and duration:\n");
255 fprintf(stderr, "\t b [vol [pitch [dur]]] b on\n"); 250 fprintf(stderr, "\t b [vol [pitch [dur]]] b on\n");
256 fprintf(stderr, " To restore default voice parameter:\n"); 251 fprintf(stderr, " To restore default voice parameter:\n");
257 fprintf(stderr, "\t v default\n"); 252 fprintf(stderr, "\t v default\n");
258 fprintf(stderr, " To set voice parameter:\n"); 253 fprintf(stderr, " To set voice parameter:\n");
259 fprintf(stderr, "\t-v voicefile\n"); 254 fprintf(stderr, "\t-v voicefile\n");
260 exit(0); 255 exit(0);
261} 256}