From: drowe67 Date: Sat, 18 Sep 2010 23:32:52 +0000 (+0000) Subject: correct error handling and menu.sh patches, thanks Bruce X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=558f89e5c7af296579a8315e4e8494cd9c351319;p=freetel-svn-tracking.git correct error handling and menu.sh patches, thanks Bruce git-svn-id: https://svn.code.sf.net/p/freetel/code@190 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/codec2/script/menu.sh b/codec2/script/menu.sh index 11297df9..d7305411 100755 --- a/codec2/script/menu.sh +++ b/codec2/script/menu.sh @@ -52,18 +52,16 @@ do shift done -readchar=1 echo -n -e "\r" $items"- " -while [ $readchar -ne 0 ] -do +while true ; do echo -n -e "\r -" - stty cbreak # or stty raw - readchar=`dd if=/dev/tty bs=1 count=1 2>/dev/null` + stty cbreak # or stty raw. Stty uses file descriptor 0, not /dev/tty. + readchar=`dd bs=1 count=1 2>/dev/null` stty -cbreak - if [ $readchar == 'q' ] ; then - readchar=0 - fi - if [ $readchar -ne 0 ] ; then + if [ -n "$readchar" ] ; then + if [ $readchar == 'q' -o $readchar == 'Q' ] ; then + exit 0 + fi play -r 8000 -s -2 ${file[$readchar]} $dsp 2> /dev/null fi done diff --git a/codec2/src/c2dec.c b/codec2/src/c2dec.c index e22757a1..6c5ecbdd 100644 --- a/codec2/src/c2dec.c +++ b/codec2/src/c2dec.c @@ -35,6 +35,8 @@ #include #include +#include +#include int main(int argc, char *argv[]) { @@ -46,19 +48,19 @@ int main(int argc, char *argv[]) if (argc != 3) { printf("usage: %s InputBitFile OutputRawSpeechFile\n", argv[0]); - exit(0); + exit(1); } - fin = fopen(argv[1],"rb"); - if (fin == NULL) { - printf("Error opening input bit file: %s\n", argv[1]); - exit(0); + if ( (fin = fopen(argv[1],"rb")) == NULL ) { + fprintf(stderr, "Error opening input bit file: %s: %s.\n", + argv[1], strerror(errno)); + exit(1); } - fout = fopen(argv[2],"wb"); - if (fout == NULL) { - printf("Error opening output speech file: %s\n", argv[2]); - exit(0); + if ( (fout = fopen(argv[2],"wb")) == NULL ) { + fprintf(stderr, "Error opening output speech file: %s: %s.\n", + argv[2], strerror(errno)); + exit(1); } codec2 = codec2_create(); diff --git a/codec2/src/c2enc.c b/codec2/src/c2enc.c index f1171c24..36cf7b86 100644 --- a/codec2/src/c2enc.c +++ b/codec2/src/c2enc.c @@ -36,6 +36,8 @@ #include #include +#include +#include int main(int argc, char *argv[]) { @@ -47,19 +49,19 @@ int main(int argc, char *argv[]) if (argc != 3) { printf("usage: %s InputRawspeechFile OutputBitFile\n", argv[0]); - exit(0); + exit(1); } - fin = fopen(argv[1],"rb"); - if (fin == NULL) { - printf("Error opening input speech file: %s\n", argv[1]); - exit(0); + if ( (fin = fopen(argv[1],"rb")) == NULL ) { + fprintf(stderr, "Error opening input bit file: %s: %s.\n", + argv[1], strerror(errno)); + exit(1); } - fout = fopen(argv[2],"wb"); - if (fout == NULL) { - printf("Error opening output bit file: %s\n", argv[2]); - exit(0); + if ( (fout = fopen(argv[2],"wb")) == NULL ) { + fprintf(stderr, "Error opening output speech file: %s: %s.\n", + argv[2], strerror(errno)); + exit(1); } codec2 = codec2_create(); diff --git a/codec2/src/c2sim.c b/codec2/src/c2sim.c index 08748b91..68aa18f1 100644 --- a/codec2/src/c2sim.c +++ b/codec2/src/c2sim.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include "defines.h" @@ -140,17 +141,17 @@ int main(int argc, char *argv[]) nlp_states = nlp_create(); if (argc < 2) { - printf("\nCodec2 - 2400 bit/s speech codec - Simulation Program\n"); - printf(" http://rowetel.com/codec2.html\n\n"); - printf("usage: %s InputFile [-o OutputFile]\n", argv[0]); - printf(" [-o lpc Order]\n"); - printf(" [--lsp]\n"); - printf(" [--phase0]\n"); - printf(" [--postfilter]\n"); - printf(" [--hand_voicing]\n"); - printf(" [--dec]\n"); - printf(" [--dump DumpFilePrefix]\n"); - exit(0); + fprintf(stderr, "\nCodec2 - 2400 bit/s speech codec - Simulation Program\n" + "\thttp://rowetel.com/codec2.html\n\n" + "usage: %s InputFile [-o OutputFile]\n" + "\t[-o lpc Order]\n" + "\t[--lsp]\n" + "\t[--phase0]\n" + "\t[--postfilter]\n" + "\t[--hand_voicing]\n" + "\t[--dec]\n" + "\t[--dump DumpFilePrefix]\n", argv[0]); + exit(1); } /* Interpret command line arguments -------------------------------------*/ @@ -158,7 +159,8 @@ int main(int argc, char *argv[]) /* Input file */ if ((fin = fopen(argv[1],"rb")) == NULL) { - printf("Error opening input speech file: %s\n",argv[1]); + fprintf(stderr, "Error opening input bit file: %s: %s.\n", + argv[1], strerror(errno)); exit(1); } @@ -166,7 +168,8 @@ int main(int argc, char *argv[]) if ((arg = switch_present("-o",argc,argv))) { if ((fout = fopen(argv[arg+1],"wb")) == NULL) { - printf("Error opening output speech file: %s\n",argv[arg+1]); + fprintf(stderr, "Error opening output speech file: %s: %s.\n", + argv[arg+1], strerror(errno)); exit(1); } strcpy(out_file,argv[arg+1]); @@ -179,7 +182,7 @@ int main(int argc, char *argv[]) lpc_model = 1; order = atoi(argv[arg+1]); if ((order < 4) || (order > 20)) { - printf("Error in lpc order: %d\n", order); + fprintf(stderr, "Error in lpc order: %d\n", order); exit(1); } }