1 /*------------- Telecommunications & Signal Processing Lab -------------
2 McGill University
3
4 Routine:
5 void LSoptions (int argc, const char *argv[], char Fname[4][FILENAME_MAX])
6
7 Purpose:
8 Decode options for LPsyn
9
10 Description:
11 This routine decodes options for LPsyn.
12
13 Parameters:
14 -> int argc
15 Number of command line arguments
16 -> const char *argv[]
17 Array of pointers to argument strings
18 <- const char *Fname[4]
19 File names: input parameter file,
20 input audio file,
21 LPC file,
22 output audio file
23
24 Author / revision:
25 P. Kabal Copyright (C) 2003
26 $Revision: 1.2 $ $Date: 2003/05/13 01:18:00 $
27
28 ----------------------------------------------------------------------*/
29
30 #include <stdlib.h> /* prototype for exit */
31
32 #include <libtsp.h>
33 #include <libtsp/AFpar.h>
34
35 #include "LPsyn.h"
36
37 #ifndef EXIT_SUCCESS
38 # define EXIT_SUCCESS 0 /* Normally in stdlib.h */
39 #endif
40
41 #define NELEM(array) ((sizeof array) / (sizeof array[0]))
42
43 /* Option tables and usage message */
44 #define LOPT (NELEM (OptTable) / 2)
45 static const char *nullTable[] = { NULL };
46 static const char *OptTable[] = {
47 "-p#", "--par*ameter_file=",
48 "-c#", "--lpc*_file=",
49 "-h", "--h*elp",
50 "-v", "--v*ersion",
51 "--",
52 NULL
53 };
54 static const char Usage[] = "\
55 Usage: %s [options] AFileI [AFileO]\n\
56 Options:\n\
57 -p Pfile, --parameter_file=Pfile,\n\
58 Parameter file.\n\
59 -c LPFile, --lpc_file=LPFile\n\
60 LPC predictor coefficient file.\n\
61 -h, --help Print a list of options and exit.\n\
62 -v, --version Print the version number and exit.";
63
64 void
LSoptions(int argc,const char * argv[],char Fname[4][FILENAME_MAX])65 LSoptions (int argc, const char *argv[], char Fname[4][FILENAME_MAX])
66
67 {
68 int Index;
69 const char *OptArg;
70 const char **optt;
71
72 int nF, n, nn;
73
74 /* Defaults */
75 Fname[2][0] = '\0';
76 Fname[3][0] = '\0';
77
78 /* Initialization */
79 UTsetProg (PROGRAM);
80 nF = 0;
81
82 /* Decode options */
83 Index = 1;
84 optt = OptTable;
85 while (Index < argc) {
86 n = UTgetOption (&Index, argc, argv, optt, &OptArg);
87 nn = ((n + 3) / 2) - 1; /* n = -2 ==> nn = -1 */
88 switch (nn) {
89 case 0:
90 /* Filename argument */
91 ++nF;
92 if (nF == 1)
93 STcopyMax (OptArg, Fname[1], FILENAME_MAX-1);
94 else if (nF == 2)
95 STcopyMax (OptArg, Fname[3], FILENAME_MAX-1);
96 else
97 UThalt ("%s: Too many filenames specified", PROGRAM);
98 break;
99 case 1:
100 /* Parameter file */
101 STcopyMax (OptArg, Fname[0], FILENAME_MAX-1);
102 break;
103 case 2:
104 /* LPC file */
105 STcopyMax (OptArg, Fname[2], FILENAME_MAX-1);
106 break;
107 case LOPT-2:
108 /* Help */
109 UTwarn (Usage, PROGRAM);
110 exit (EXIT_SUCCESS);
111 break;
112 case LOPT-1:
113 /* Version */
114 printf ("%s: %s\n", PROGRAM, VERSION);
115 exit (EXIT_SUCCESS);
116 break;
117 case LOPT:
118 /* Stop interpreting options */
119 optt = nullTable;
120 break;
121 default:
122 /* Option error */
123 UThalt (Usage, PROGRAM);
124 break;
125 }
126 }
127
128 /* Checks */
129 if (nF < 1)
130 UThalt ("%s: No input audio file", PROGRAM);
131 if (Fname[0][0] == '\0')
132 UThalt ("%s: No parameter file", PROGRAM);
133 if (Fname[2][0] == '\0')
134 UThalt ("%s: No LPC coefficient file", PROGRAM);
135
136 return;
137 }
138