]> git.deb.at Git - pkg/beep.git/blobdiff - beep.c
Gerfried's devfs fix
[pkg/beep.git] / beep.c
diff --git a/beep.c b/beep.c
index a0da2d3fb488c6875b0041d5be215e25ace1cabe..a3a01318ed827ce1fd4a9d37bea9426f3f221898 100644 (file)
--- a/beep.c
+++ b/beep.c
@@ -159,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 */
@@ -201,8 +204,10 @@ 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;
@@ -220,6 +225,8 @@ void parse_command_line(int argc, char **argv, beep_parms_t *result) {
       usage_bail(argv[0]);
     }
   }
+  if (result->freq == 0)
+    result->freq = DEFAULT_FREQ;
 }  
 
 void play_beep(beep_parms_t parms) {
@@ -231,11 +238,13 @@ void play_beep(beep_parms_t parms) {
        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");
-    printf("\a");  /* Output the only beep we can, in an effort to fall back on usefulness */
-    perror("open");
-    exit(1);
+  if((console_fd = open("/dev/tty0", O_WRONLY)) == -1) {
+    if((console_fd = open("/dev/vc/0", O_WRONLY)) == -1) {
+      fprintf(stderr, "Could not open /dev/tty0 or /dev/vc/0 for writing.\n");
+      printf("\a");  /* Output the only beep we can, in an effort to fall back on usefulness */
+      perror("open");
+      exit(1);
+    }
   }
   
   /* Beep */
@@ -260,7 +269,7 @@ 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;