diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-08-22 18:00:39 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-08-22 18:00:39 +0200 |
commit | 0da1c0a73298087def5f42be61913b79fd2d9193 (patch) | |
tree | 384d36e5d927853f10b25dc5dbdec965549e4f55 | |
parent | dc3d8939d464e3de2bd47b6936f06d07ea58c75e (diff) | |
download | busybox-w32-0da1c0a73298087def5f42be61913b79fd2d9193.tar.gz busybox-w32-0da1c0a73298087def5f42be61913b79fd2d9193.tar.bz2 busybox-w32-0da1c0a73298087def5f42be61913b79fd2d9193.zip |
beep: optimize
function old new delta
beep_main 394 276 -118
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | TODO_config_nommu | 3 | ||||
-rw-r--r-- | miscutils/Config.in | 2 | ||||
-rw-r--r-- | miscutils/beep.c | 122 | ||||
-rw-r--r-- | scripts/defconfig | 2 |
4 files changed, 60 insertions, 69 deletions
diff --git a/TODO_config_nommu b/TODO_config_nommu index 43d5420a8..1835b6e80 100644 --- a/TODO_config_nommu +++ b/TODO_config_nommu | |||
@@ -567,6 +567,9 @@ CONFIG_FEATURE_MOUNT_LOOP=y | |||
567 | # | 567 | # |
568 | CONFIG_ADJTIMEX=y | 568 | CONFIG_ADJTIMEX=y |
569 | CONFIG_BBCONFIG=y | 569 | CONFIG_BBCONFIG=y |
570 | CONFIG_BEEP=y | ||
571 | CONFIG_FEATURE_BEEP_FREQ=4000 | ||
572 | CONFIG_FEATURE_BEEP_LENGTH_MS=30 | ||
570 | CONFIG_CHAT=y | 573 | CONFIG_CHAT=y |
571 | CONFIG_FEATURE_CHAT_NOFAIL=y | 574 | CONFIG_FEATURE_CHAT_NOFAIL=y |
572 | CONFIG_FEATURE_CHAT_TTY_HIFI=y | 575 | CONFIG_FEATURE_CHAT_TTY_HIFI=y |
diff --git a/miscutils/Config.in b/miscutils/Config.in index 4e19bd8c4..9a81ecc6b 100644 --- a/miscutils/Config.in +++ b/miscutils/Config.in | |||
@@ -33,7 +33,7 @@ config FEATURE_BEEP_FREQ | |||
33 | help | 33 | help |
34 | Frequency for default beep. | 34 | Frequency for default beep. |
35 | 35 | ||
36 | config FEATURE_BEEP_LENGTH | 36 | config FEATURE_BEEP_LENGTH_MS |
37 | int "default length" | 37 | int "default length" |
38 | range 0 2147483647 | 38 | range 0 2147483647 |
39 | default 30 | 39 | default 30 |
diff --git a/miscutils/beep.c b/miscutils/beep.c index 79e75473c..f3266dc2d 100644 --- a/miscutils/beep.c +++ b/miscutils/beep.c | |||
@@ -11,92 +11,80 @@ | |||
11 | 11 | ||
12 | #include <linux/kd.h> | 12 | #include <linux/kd.h> |
13 | #ifndef CLOCK_TICK_RATE | 13 | #ifndef CLOCK_TICK_RATE |
14 | #define CLOCK_TICK_RATE 1193180 | 14 | # define CLOCK_TICK_RATE 1193180 |
15 | #endif | 15 | #endif |
16 | 16 | ||
17 | #define OPT_f (1<<0) | ||
18 | #define OPT_l (1<<1) | ||
19 | #define OPT_d (1<<2) | ||
20 | #define OPT_r (1<<3) | ||
21 | /* defaults */ | 17 | /* defaults */ |
22 | #ifndef CONFIG_FEATURE_BEEP_FREQ | 18 | #ifndef CONFIG_FEATURE_BEEP_FREQ |
23 | # define FREQ (4000) | 19 | # define FREQ (4000) |
24 | #else | 20 | #else |
25 | # define FREQ (CONFIG_FEATURE_BEEP_FREQ) | 21 | # define FREQ (CONFIG_FEATURE_BEEP_FREQ) |
26 | #endif | 22 | #endif |
27 | #ifndef CONFIG_FEATURE_BEEP_LENGTH | 23 | #ifndef CONFIG_FEATURE_BEEP_LENGTH_MS |
28 | # define LENGTH (30) | 24 | # define LENGTH (30) |
29 | #else | 25 | #else |
30 | # define LENGTH (CONFIG_FEATURE_BEEP_LENGTH) | 26 | # define LENGTH (CONFIG_FEATURE_BEEP_LENGTH_MS) |
31 | #endif | 27 | #endif |
32 | #define DELAY (0) | 28 | #define DELAY (0) |
33 | #define REPETITIONS (1) | 29 | #define REPETITIONS (1) |
34 | 30 | ||
35 | #define GET_ARG do { if (!*++opt) opt = *++argv; if (opt == NULL) bb_show_usage();} while (0) | ||
36 | #define NEW_BEEP() { \ | ||
37 | freq = FREQ; \ | ||
38 | length = LENGTH; \ | ||
39 | delay = DELAY; \ | ||
40 | rep = REPETITIONS; \ | ||
41 | } | ||
42 | |||
43 | int beep_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 31 | int beep_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
44 | int beep_main(int argc UNUSED_PARAM, char **argv) | 32 | int beep_main(int argc, char **argv) |
45 | { | 33 | { |
46 | int speaker = get_console_fd_or_die(); | 34 | int speaker = get_console_fd_or_die(); |
47 | unsigned freq, length, delay, rep; | 35 | unsigned length, delay, rep; |
48 | unsigned long ioctl_arg; | 36 | unsigned tickrate_div_freq; |
49 | char *opt = NULL; | 37 | int c; |
50 | bool do_parse = true; | ||
51 | |||
52 | NEW_BEEP() | ||
53 | while (*argv && *++argv) { | ||
54 | opt = *argv; | ||
55 | 38 | ||
56 | while (*opt == '-') | 39 | c = 'n'; |
57 | ++opt; | 40 | while (c != -1) { |
58 | if (do_parse) | 41 | if (c == 'n') { |
59 | switch (*opt) { | 42 | tickrate_div_freq = CLOCK_TICK_RATE / FREQ; |
60 | case 'f': | 43 | length = LENGTH; |
61 | GET_ARG; | 44 | delay = DELAY; |
62 | freq = xatoul(opt); | 45 | rep = REPETITIONS; |
63 | continue; | 46 | } |
64 | case 'l': | 47 | c = getopt(argc, argv, "f:l:d:r:n"); |
65 | GET_ARG; | 48 | /* TODO: -s, -c: |
66 | length = xatoul(opt); | 49 | * pipe stdin to stdout, but also beep after each line (-s) or char (-c) |
67 | continue; | 50 | */ |
68 | case 'd': | 51 | switch (c) { |
69 | GET_ARG; | 52 | case 'f': |
70 | delay = xatoul(opt); | 53 | /* TODO: what "-f 0" should do? */ |
71 | continue; | 54 | tickrate_div_freq = (unsigned)CLOCK_TICK_RATE / xatou(optarg); |
72 | case 'r': | 55 | continue; |
73 | GET_ARG; | 56 | case 'l': |
74 | rep = xatoul(opt); | 57 | length = xatou(optarg); |
75 | continue; | 58 | continue; |
76 | case 'n': | 59 | case 'd': |
77 | break; | 60 | /* TODO: |
78 | default: | 61 | * -d N, -D N |
79 | bb_show_usage(); | 62 | * specify a delay of N milliseconds between repetitions. |
80 | break; | 63 | * -d specifies that this delay should only occur between beeps, |
81 | } | 64 | * that is, it should not occur after the last repetition. |
82 | again: | 65 | * -D indicates that the delay should occur after every repetition |
66 | */ | ||
67 | delay = xatou(optarg); | ||
68 | continue; | ||
69 | case 'r': | ||
70 | rep = xatou(optarg); | ||
71 | continue; | ||
72 | case 'n': | ||
73 | case -1: | ||
74 | break; | ||
75 | default: | ||
76 | bb_show_usage(); | ||
77 | } | ||
83 | while (rep) { | 78 | while (rep) { |
84 | //bb_info_msg("rep[%d] freq=%d, length=%d, delay=%d", rep, freq, length, delay); | 79 | //bb_info_msg("rep[%d] freq=%d, length=%d, delay=%d", rep, freq, length, delay); |
85 | ioctl_arg = (int)(CLOCK_TICK_RATE/freq); | 80 | xioctl(speaker, KIOCSOUND, (void*)(long)tickrate_div_freq); |
86 | xioctl(speaker, KIOCSOUND, (void*)ioctl_arg); | ||
87 | usleep(1000 * length); | 81 | usleep(1000 * length); |
88 | ioctl(speaker, KIOCSOUND, 0); | 82 | ioctl(speaker, KIOCSOUND, (void*)0); |
89 | if (rep--) | 83 | if (--rep) |
90 | usleep(delay); | 84 | usleep(delay); |
91 | } | 85 | } |
92 | if (opt && *opt == 'n') | ||
93 | NEW_BEEP() | ||
94 | if (!do_parse && *argv == NULL) | ||
95 | goto out; | ||
96 | } | 86 | } |
97 | do_parse = false; | 87 | |
98 | goto again; | ||
99 | out: | ||
100 | if (ENABLE_FEATURE_CLEAN_UP) | 88 | if (ENABLE_FEATURE_CLEAN_UP) |
101 | close(speaker); | 89 | close(speaker); |
102 | return EXIT_SUCCESS; | 90 | return EXIT_SUCCESS; |
@@ -117,11 +105,11 @@ g=$((392*3)) | |||
117 | -n -f$g -l200 -r2 \ | 105 | -n -f$g -l200 -r2 \ |
118 | -n -f$f -l200 \ | 106 | -n -f$f -l200 \ |
119 | -n -f$e -l200 \ | 107 | -n -f$e -l200 \ |
120 | -n -f$d -l200 \ | 108 | -n -f$d -l200 \ |
121 | -n -f$c -l200 -r2 \ | 109 | -n -f$c -l200 -r2 \ |
122 | -n -f$d -l200 \ | 110 | -n -f$d -l200 \ |
123 | -n -f$e -l200 \ | 111 | -n -f$e -l200 \ |
124 | -n -f$e -l400 \ | 112 | -n -f$e -l400 \ |
125 | -n -f$d -l100 \ | 113 | -n -f$d -l100 \ |
126 | -n -f$d -l200 \ | 114 | -n -f$d -l200 \ |
127 | */ | 115 | */ |
diff --git a/scripts/defconfig b/scripts/defconfig index 394839bc9..797f275d1 100644 --- a/scripts/defconfig +++ b/scripts/defconfig | |||
@@ -569,7 +569,7 @@ CONFIG_ADJTIMEX=y | |||
569 | # CONFIG_BBCONFIG is not set | 569 | # CONFIG_BBCONFIG is not set |
570 | CONFIG_BEEP=y | 570 | CONFIG_BEEP=y |
571 | CONFIG_FEATURE_BEEP_FREQ=4000 | 571 | CONFIG_FEATURE_BEEP_FREQ=4000 |
572 | CONFIG_FEATURE_BEEP_LENGTH=30 | 572 | CONFIG_FEATURE_BEEP_LENGTH_MS=30 |
573 | CONFIG_CHAT=y | 573 | CONFIG_CHAT=y |
574 | CONFIG_FEATURE_CHAT_NOFAIL=y | 574 | CONFIG_FEATURE_CHAT_NOFAIL=y |
575 | # CONFIG_FEATURE_CHAT_TTY_HIFI is not set | 575 | # CONFIG_FEATURE_CHAT_TTY_HIFI is not set |