On Friday 21 August 2009 11:21, Bernhard Reutner-Fischer wrote:
> On Wed, Aug 19, 2009 at 11:46:26PM +0200, Bernhard Reutner-Fischer wrote:
> >On Wed, Aug 19, 2009 at 12:12:17PM -0700, Nathan Angelacos wrote:
>
> updated full patch is attached (which also handles 'beep -d' like it
> should)
Is there some quirk in command line format which prevents usage
of getopt()?
while (rep) {
ioctl_arg = (int)(CLOCK_TICK_RATE/freq);
xioctl(speaker, KIOCSOUND, (void*)ioctl_arg);
usleep(1000 * length);
ioctl(speaker, KIOCSOUND, 0);
if (rep--)
usleep(delay);
}
"if (rep--)" is always true. did you mean "if (--rep)"?
I propose the following two patches.
function old new delta
beep_main 394 269 -125
--
vda
diff -d -urpN busybox.0/miscutils/beep.c busybox.1/miscutils/beep.c
--- busybox.0/miscutils/beep.c 2009-08-22 14:52:14.000000000 +0200
+++ busybox.1/miscutils/beep.c 2009-08-22 15:44:17.000000000 +0200
@@ -18,27 +18,34 @@
#define OPT_l (1<<1)
#define OPT_d (1<<2)
#define OPT_r (1<<3)
+
/* defaults */
#ifndef CONFIG_FEATURE_BEEP_FREQ
# define FREQ (4000)
#else
# define FREQ (CONFIG_FEATURE_BEEP_FREQ)
#endif
-#ifndef CONFIG_FEATURE_BEEP_LENGTH
+#ifndef CONFIG_FEATURE_BEEP_LENGTH_MS
# define LENGTH (30)
#else
-# define LENGTH (CONFIG_FEATURE_BEEP_LENGTH)
+# define LENGTH (CONFIG_FEATURE_BEEP_LENGTH_MS)
#endif
#define DELAY (0)
#define REPETITIONS (1)
-#define GET_ARG do { if (!*++opt) opt = *++argv; if (opt == NULL) bb_show_usage();} while (0)
-#define NEW_BEEP() { \
+#define GET_ARG do { \
+ if (!*++opt) \
+ opt = *++argv; \
+ if (opt == NULL) \
+ bb_show_usage(); \
+} while (0)
+
+#define NEW_BEEP do { \
freq = FREQ; \
length = LENGTH; \
delay = DELAY; \
rep = REPETITIONS; \
- }
+} while (0)
int beep_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int beep_main(int argc UNUSED_PARAM, char **argv)
@@ -49,7 +56,7 @@ int beep_main(int argc UNUSED_PARAM, cha
char *opt = NULL;
bool do_parse = true;
- NEW_BEEP()
+ NEW_BEEP;
while (*argv && *++argv) {
opt = *argv;
@@ -90,7 +97,7 @@ int beep_main(int argc UNUSED_PARAM, cha
usleep(delay);
}
if (opt && *opt == 'n')
- NEW_BEEP()
+ NEW_BEEP;
if (!do_parse && *argv == NULL)
goto out;
}
@@ -117,11 +124,11 @@ g=$((392*3))
-n -f$g -l200 -r2 \
-n -f$f -l200 \
-n -f$e -l200 \
- -n -f$d -l200 \
- -n -f$c -l200 -r2 \
- -n -f$d -l200 \
- -n -f$e -l200 \
- -n -f$e -l400 \
+ -n -f$d -l200 \
+ -n -f$c -l200 -r2 \
+ -n -f$d -l200 \
+ -n -f$e -l200 \
+ -n -f$e -l400 \
-n -f$d -l100 \
-n -f$d -l200 \
*/
diff -d -urpN busybox.0/miscutils/Config.in busybox.1/miscutils/Config.in
--- busybox.0/miscutils/Config.in 2009-08-22 14:52:14.000000000 +0200
+++ busybox.1/miscutils/Config.in 2009-08-22 15:44:17.000000000 +0200
@@ -33,7 +33,7 @@ config FEATURE_BEEP_FREQ
help
Frequency for default beep.
-config FEATURE_BEEP_LENGTH
+config FEATURE_BEEP_LENGTH_MS
int "default length"
range 0 2147483647
default 30
diff -d -urpN busybox.0/scripts/defconfig busybox.1/scripts/defconfig
--- busybox.0/scripts/defconfig 2009-08-22 14:52:14.000000000 +0200
+++ busybox.1/scripts/defconfig 2009-08-22 15:44:17.000000000 +0200
@@ -569,7 +569,7 @@ CONFIG_ADJTIMEX=y
# CONFIG_BBCONFIG is not set
CONFIG_BEEP=y
CONFIG_FEATURE_BEEP_FREQ=4000
-CONFIG_FEATURE_BEEP_LENGTH=30
+CONFIG_FEATURE_BEEP_LENGTH_MS=30
CONFIG_CHAT=y
CONFIG_FEATURE_CHAT_NOFAIL=y
# CONFIG_FEATURE_CHAT_TTY_HIFI is not set
diff -d -urpN busybox.1/miscutils/beep.c busybox.2/miscutils/beep.c
--- busybox.1/miscutils/beep.c 2009-08-22 15:44:17.000000000 +0200
+++ busybox.2/miscutils/beep.c 2009-08-22 15:43:38.000000000 +0200
@@ -14,11 +14,6 @@
#define CLOCK_TICK_RATE 1193180
#endif
-#define OPT_f (1<<0)
-#define OPT_l (1<<1)
-#define OPT_d (1<<2)
-#define OPT_r (1<<3)
-
/* defaults */
#ifndef CONFIG_FEATURE_BEEP_FREQ
# define FREQ (4000)
@@ -33,13 +28,6 @@
#define DELAY (0)
#define REPETITIONS (1)
-#define GET_ARG do { \
- if (!*++opt) \
- opt = *++argv; \
- if (opt == NULL) \
- bb_show_usage(); \
-} while (0)
-
#define NEW_BEEP do { \
freq = FREQ; \
length = LENGTH; \
@@ -48,62 +36,48 @@
} while (0)
int beep_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int beep_main(int argc UNUSED_PARAM, char **argv)
+int beep_main(int argc, char **argv)
{
int speaker = get_console_fd_or_die();
unsigned freq, length, delay, rep;
unsigned long ioctl_arg;
- char *opt = NULL;
- bool do_parse = true;
-
- NEW_BEEP;
- while (*argv && *++argv) {
- opt = *argv;
+ int c;
- while (*opt == '-')
- ++opt;
- if (do_parse)
- switch (*opt) {
- case 'f':
- GET_ARG;
- freq = xatoul(opt);
- continue;
- case 'l':
- GET_ARG;
- length = xatoul(opt);
- continue;
- case 'd':
- GET_ARG;
- delay = xatoul(opt);
- continue;
- case 'r':
- GET_ARG;
- rep = xatoul(opt);
- continue;
- case 'n':
- break;
- default:
- bb_show_usage();
- break;
- }
- again:
+ c = 'n';
+ while (c != -1) {
+ if (c == 'n')
+ NEW_BEEP;
+ c = getopt(argc, argv, "f:l:d:r:n");
+ switch (c) {
+ case 'f':
+ freq = xatoul(optarg);
+ continue;
+ case 'l':
+ length = xatoul(optarg);
+ continue;
+ case 'd':
+ delay = xatoul(optarg);
+ continue;
+ case 'r':
+ rep = xatoul(optarg);
+ continue;
+ case 'n':
+ case -1:
+ break;
+ default:
+ bb_show_usage();
+ }
while (rep) {
//bb_info_msg("rep[%d] freq=%d, length=%d, delay=%d", rep, freq, length, delay);
ioctl_arg = (int)(CLOCK_TICK_RATE/freq);
xioctl(speaker, KIOCSOUND, (void*)ioctl_arg);
usleep(1000 * length);
ioctl(speaker, KIOCSOUND, 0);
- if (rep--)
+ if (--rep)
usleep(delay);
}
- if (opt && *opt == 'n')
- NEW_BEEP;
- if (!do_parse && *argv == NULL)
- goto out;
}
- do_parse = false;
- goto again;
- out:
+
if (ENABLE_FEATURE_CLEAN_UP)
close(speaker);
return EXIT_SUCCESS;
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox