correct error handling and menu.sh patches, thanks Bruce
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Sat, 18 Sep 2010 23:32:52 +0000 (23:32 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Sat, 18 Sep 2010 23:32:52 +0000 (23:32 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@190 01035d8c-6547-0410-b346-abe4f91aad63

codec2/script/menu.sh
codec2/src/c2dec.c
codec2/src/c2enc.c
codec2/src/c2sim.c

index 11297df9b93818b0ac1071d4347029806156b131..d7305411dc39b61f6e73943f7bed77f91b9819e9 100755 (executable)
@@ -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
index e22757a13d53fc6c4d5dfe317493497bb83adc2d..6c5ecbdd7c6ffb64b5c1682ef32ff26817cfcd21 100644 (file)
@@ -35,6 +35,8 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
+#include <errno.h>
 
 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();
index f1171c2425f0fe3fc9b74125b2321810a8e4850c..36cf7b8681ce07ce12e087b575eb04188b432e71 100644 (file)
@@ -36,6 +36,8 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
+#include <errno.h>
 
 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();
index 08748b912f58d15a8fd7c49aaa9a678c4e2a4bb5..68aa18f1b21dbdc8b38634a8f1108f4a52cab173 100644 (file)
@@ -31,6 +31,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <errno.h>
 #include <math.h>
 
 #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);
       }          
   }