X-Git-Url: https://git.deb.at/w?p=pkg%2Fbeep.git;a=blobdiff_plain;f=beep.c;h=90ec8370dba1165c7eafc82d4aa3ee483b99911a;hp=f774b56247d9fba66f9cfdff011708a985dee727;hb=0d0b32d3e8add7daedb82e565ffe2028d7e0eed0;hpb=56a28a6ccda7e1a39513dac1ff95396a6cf6b60d diff --git a/beep.c b/beep.c index f774b56..90ec837 100644 --- a/beep.c +++ b/beep.c @@ -83,6 +83,7 @@ typedef struct beep_parms_t { so that beep can be tucked appropriately into a text- processing pipe. */ + int verbose; /* verbose output? */ struct beep_parms_t *next; /* in case -n/--new is used. */ } beep_parms_t; @@ -110,7 +111,7 @@ void handle_signal(int signum) { /* print usage and exit */ void usage_bail(const char *executable_name) { printf("Usage:\n%s [-f freq] [-l length] [-r reps] [-d delay] " - "[-D delay] [-s] [-c]\n", + "[-D delay] [-s] [-c] [--verbose | --debug]\n", executable_name); printf("%s [Options...] [-n] [--new] [Options...] ... \n", executable_name); printf("%s [-h] [--help]\n", executable_name); @@ -131,6 +132,7 @@ void usage_bail(const char *executable_name) { * "-D " (similar to -d, but delay after last repetition as well) * "-s" (beep after each line of input from stdin, echo line to stdout) * "-c" (beep after each char of input from stdin, echo char to stdout) + * "--verbose/--debug" * "-h/--help" * "-v/-V/--version" * "-n/--new" @@ -141,9 +143,11 @@ void usage_bail(const char *executable_name) { void parse_command_line(int argc, char **argv, beep_parms_t *result) { int c; - struct option opt_list[4] = {{"help", 0, NULL, 'h'}, + struct option opt_list[6] = {{"help", 0, NULL, 'h'}, {"version", 0, NULL, 'V'}, {"new", 0, NULL, 'n'}, + {"verbose", 0, NULL, 'X'}, + {"debug", 0, NULL, 'X'}, {0,0,0,0}}; while((c = getopt_long(argc, argv, "f:l:r:d:D:schvVn", opt_list, NULL)) != EOF) { @@ -155,6 +159,9 @@ void parse_command_line(int argc, char **argv, beep_parms_t *result) { (argfreq <= 0)) usage_bail(argv[0]); else + if (result->freq != 0) + fprintf(stderr, "WARNING: multiple -f values given, only last " + "one is used.\n"); result->freq = argfreq; break; case 'l' : /* length */ @@ -197,29 +204,42 @@ void parse_command_line(int argc, char **argv, beep_parms_t *result) { exit(0); break; case 'n' : /* also --new - create another beep */ + if (result->freq == 0) + result->freq = DEFAULT_FREQ; result->next = (beep_parms_t *)malloc(sizeof(beep_parms_t)); - result->next->freq = DEFAULT_FREQ; + result->next->freq = 0; result->next->length = DEFAULT_LENGTH; result->next->reps = DEFAULT_REPS; result->next->delay = DEFAULT_DELAY; result->next->end_delay = DEFAULT_END_DELAY; result->next->stdin_beep = DEFAULT_STDIN_BEEP; + result->next->verbose = result->verbose; result->next->next = NULL; result = result->next; /* yes, I meant to do that. */ break; + case 'X' : /* --debug / --verbose */ + result->verbose = 1; + break; case 'h' : /* notice that this is also --help */ default : usage_bail(argv[0]); } } + if (result->freq == 0) + result->freq = DEFAULT_FREQ; } void play_beep(beep_parms_t parms) { int i; /* loop counter */ + if(parms.verbose == 1) + fprintf(stderr, "[DEBUG] %d times %d ms beeps (%d delay between, " + "%d delay after) @ %.2f Hz\n", + parms.reps, parms.length, parms.delay, parms.end_delay, parms.freq); + /* try to snag the console */ - if((console_fd = open("/dev/console", O_WRONLY)) == -1) { - fprintf(stderr, "Could not open /dev/console for writing.\n"); + if((console_fd = open("/dev/tty0", O_WRONLY)) == -1) { + fprintf(stderr, "Could not open /dev/tty0 for writing.\n"); printf("\a"); /* Output the only beep we can, in an effort to fall back on usefulness */ perror("open"); exit(1); @@ -247,12 +267,13 @@ int main(int argc, char **argv) { char sin[4096], *ptr; beep_parms_t *parms = (beep_parms_t *)malloc(sizeof(beep_parms_t)); - parms->freq = DEFAULT_FREQ; + parms->freq = 0; parms->length = DEFAULT_LENGTH; parms->reps = DEFAULT_REPS; parms->delay = DEFAULT_DELAY; parms->end_delay = DEFAULT_END_DELAY; parms->stdin_beep = DEFAULT_STDIN_BEEP; + parms->verbose = 0; parms->next = NULL; signal(SIGINT, handle_signal);