Holger Levsen <hol...@layer-acht.org> writes: > sounds good to me.
OK, then here are some initial patches. I've also included checks for unexpected arguments, and support (assuming ?= is ok) for overriding CFLAGS. Let me know if you see anything you'd like fixed.
>From d3067c4bf1c17c7ea7eda8e90819b0cb94c2172f Mon Sep 17 00:00:00 2001 From: Rob Browning <r...@defaultvalue.org> Date: Wed, 29 Feb 2012 21:44:36 -0600 Subject: [PATCH 1/4] Use CFLAGS when building saytime. --- Makefile | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/Makefile b/Makefile index 91217d8..85762b8 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,9 @@ # Makefile for saytime. +CFLAGS ?= -O + saytime: saytime.c - cc -O -DSOUND_DIR=\"/usr/share/saytime\" saytime.c -o saytime + cc ${CFLAGS} -DSOUND_DIR=\"/usr/share/saytime\" saytime.c -o saytime clean: rm -f saytime -- 1.7.9.1
>From 51ca759fa086165776241f68bb65251d0b17dd4f Mon Sep 17 00:00:00 2001 From: Rob Browning <r...@defaultvalue.org> Date: Wed, 29 Feb 2012 22:11:41 -0600 Subject: [PATCH 2/4] Check for unhandled arguments. --- saytime.c | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-) diff --git a/saytime.c b/saytime.c index d84f17e..c08e587 100644 --- a/saytime.c +++ b/saytime.c @@ -160,6 +160,15 @@ char *argv[]; } } + if(optind != argc) { + int i; + fprintf(stderr, "Unexpected arguments:"); + for(i = optind; i < argc; i++) + fprintf(stderr, " %s", argv[i]); + fputc('\n', stderr); + usage(); + } + if (opt_to_stdout && opt_sound_device != NULL) { printf("Specifying alternate device and stdout makes no sense.\n"); usage(); -- 1.7.9.1
>From 81c5ccf9716d88ef17e7f988747e7ba2ac23d332 Mon Sep 17 00:00:00 2001 From: Rob Browning <r...@defaultvalue.org> Date: Sat, 3 Mar 2012 14:45:03 -0600 Subject: [PATCH 3/4] Add alsa support; allow selection of output type via '-t'. See the changes to the saytime.1 manpage for further information. --- debian/saytime.1 | 11 ++++++++++- saytime.c | 47 ++++++++++++++++++++++++++++++++++------------- 2 files changed, 44 insertions(+), 14 deletions(-) diff --git a/debian/saytime.1 b/debian/saytime.1 index 945f73d..c0ebcdd 100644 --- a/debian/saytime.1 +++ b/debian/saytime.1 @@ -15,6 +15,9 @@ saytime \- audio time check [ .BI "\-o" " dev" ] +[ +.BI "\-t" " output\-type" +] .br .SH DESCRIPTION .I saytime @@ -43,7 +46,13 @@ below). Display simple help. .TP .BI "\-o" " dev" -Output to alternate file (default /dev/audio). +Output to alternate file. If \-t is not specified with \-o, \-t +defaults to ossdsp. +.TP +.BI "\-t" " output\-type" +Specify the output type (oss, alsa, etc.); this is passed directly to +sox. If neither \-t nor \-o is specified, saytime will pick a default +destination via sox \-d. .SH FORMAT STRING A format string can be specified to control the time message. Valid format characters are: diff --git a/saytime.c b/saytime.c index c08e587..d4241eb 100644 --- a/saytime.c +++ b/saytime.c @@ -29,7 +29,6 @@ #include <sys/wait.h> #include <signal.h> -#define DEFAULT_SOUND_DEVICE "/dev/audio" #define DEFAULT_SOUND_DIR "/usr/share/saytime" #define DEFAULT_TIME_FORMAT "%P%l%M%S" #define DEFAULT_INTERVAL 1 @@ -94,6 +93,7 @@ It took about 10 minutes. #define PH_PM 36 int opt_to_stdout = 0; +char *opt_output_type = NULL; char *opt_sound_device = NULL; char *opt_sound_dir = DEFAULT_SOUND_DIR; char *opt_time_format = NULL; @@ -115,9 +115,9 @@ char *argv[]; long clock; struct tm *t; #if defined TTEST - char *opt_string="v:r:co:d:f:h:H:N:C:"; + char *opt_string="v:t:r:co:d:f:h:H:N:C:"; #else - char *opt_string="v:r:co:d:f:h"; + char *opt_string="v:t:r:co:d:f:h"; #endif int op ; pid_t fpid; @@ -149,6 +149,8 @@ char *argv[]; break; case 'c' : opt_to_stdout = 1; break; + case 't' : opt_output_type = optarg; + break; case 'o' : opt_sound_device = optarg; break; case 'd' : opt_sound_dir = optarg; @@ -173,8 +175,11 @@ char *argv[]; printf("Specifying alternate device and stdout makes no sense.\n"); usage(); } - else if (opt_sound_device == NULL) - opt_sound_device = DEFAULT_SOUND_DEVICE; + + if (opt_to_stdout && opt_output_type != NULL) { + printf("Specifying output type and stdout makes no sense.\n"); + usage(); + } if (opt_time_format == NULL) opt_time_format = DEFAULT_TIME_FORMAT; @@ -231,7 +236,7 @@ char *argv[]; void usage( ) { - fprintf( stderr, "Usage: saytime [-ch] [-v lvl] [-r sec] [-d dir] [-f fmt] [-o dev]\n" ); + fprintf( stderr, "Usage: saytime [-ch] [-v lvl] [-r sec] [-d dir] [-f fmt] [-o dev] [-t type]\n" ); fprintf( stderr, "Speak the current time through the computer's sound device.\n\n" ); fprintf( stderr, "Options:\n" ); fprintf( stderr, " -v lvl\tset volume level\n" ); @@ -242,8 +247,8 @@ usage( ) fprintf( stderr, " -f fmt\tspecify alternate time format [%s]\n", DEFAULT_TIME_FORMAT ) ; fprintf( stderr, " -h\tbrief help message\n" ); - fprintf( stderr, " -o dev\tspecify audio device [%s]\n", - DEFAULT_SOUND_DEVICE ); + fprintf( stderr, " -o dev\tspecify audio device\n"); + fprintf( stderr, " -t typ\tspecify output type (oss, alsa, ...)\n"); exit( 1 ); } @@ -688,16 +693,32 @@ sayfile( filename ) else if (pid == 0) { /* child */ + + if (opt_output_type == NULL && opt_sound_device == NULL && !opt_to_stdout) + /* Use sox's -d to pick a reasonable default output. */ + execl("/usr/bin/sox", "sox", "-r", RATE, "-q", "-v", opt_volume, + "-t.ul", "-c", "1", pathname, "-d", NULL); + if (opt_to_stdout) { - execl("/usr/bin/sox", "sox", "-r", RATE, "-q", "-v", opt_volume,"-t.ul", "-c", "1", - pathname, "-t", "raw", "/dev/stdout", NULL); + opt_output_type = "raw"; + opt_sound_device = "/dev/stdout"; } - else + else if (opt_sound_device != NULL && opt_output_type == NULL) { - execl("/usr/bin/sox", "sox", "-r", RATE, "-q", "-v", opt_volume,"-t.ul", "-c", "1", - pathname, "-t", "ossdsp", opt_sound_device, NULL); + /* Fall back to historic behavior. */ + opt_output_type = "ossdsp"; + opt_sound_device = "/dev/audio"; } + + if (opt_sound_device != NULL) + execl("/usr/bin/sox", "sox", "-r", RATE, "-q", "-v", opt_volume, + "-t.ul", "-c", "1", pathname, "-t", opt_output_type, + opt_sound_device, NULL); + else + execl("/usr/bin/sox", "sox", "-r", RATE, "-q", "-v", opt_volume, + "-t.ul", "-c", "1", pathname, "-t", opt_output_type, NULL); + fprintf(stderr, "execl failed\n"); exit(1); } -- 1.7.9.1
>From b54c35eda91bc1a987bc6809b4478a68d0c1212d Mon Sep 17 00:00:00 2001 From: Rob Browning <r...@defaultvalue.org> Date: Sat, 3 Mar 2012 14:44:20 -0600 Subject: [PATCH 4/4] Add libsox-fmt-alsa as an alternate dependency. --- debian/control | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/debian/control b/debian/control index c73e665..bb3dcdb 100644 --- a/debian/control +++ b/debian/control @@ -9,7 +9,7 @@ Vcs-Browser: http://anonscm.debian.org/git/collab-maint/saytime.git Package: saytime Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends}, sox (>= 12.17.9), libsox-fmt-oss, oss-compat +Depends: ${shlibs:Depends}, ${misc:Depends}, sox (>= 12.17.9), libsox-fmt-oss | libsox-fmt-alsa, oss-compat Description: speaks the current time through your sound card Say the current time through your sound card. Requires you have a sound output device available. -- 1.7.9.1
-- Rob Browning rlb @defaultvalue.org and @debian.org GPG as of 2002-11-03 14DD 432F AE39 534D B592 F9A0 25C8 D377 8C7E 73A4