1 /*------------- Telecommunications & Signal Processing Lab -------------
2 McGill University
3
4 Routine:
5 void IAoptions (int argc, const char *argv[], int *Icode,
6 struct IA_FIpar FI[MAXFILE], int *Nfiles)
7
8 Purpose:
9 Decode options for InfoAudio
10
11 Description:
12 This routine decodes options for InfoAudio.
13
14 Parameters:
15 -> int argc
16 Number of command line arguments
17 -> const char *argv[]
18 Array of pointers to argument strings
19 <- int *Icode
20 Flag to select the amount of output, default 7
21 <- struct IA_FIpar FI[MAXFILE]
22 Input file parameters
23 <- int *Nfiles
24 Number of input file names
25
26 Author / revision:
27 P. Kabal Copyright (C) 2003
28 $Revision: 1.31 $ $Date: 2003/05/13 01:19:47 $
29
30 ----------------------------------------------------------------------*/
31
32 #include <assert.h>
33
34 #include <libtsp.h>
35 #include <AO.h>
36 #include "InfoAudio.h"
37
38 #define ERRSTOP(text,par) UThalt ("%s: %s: \"%s\"", PROGRAM, text, par)
39
40 /* Option table */
41 static const char *OptTable[] = {
42 "-i#", "--info_code=",
43 NULL
44 };
45
46
47 void
IAoptions(int argc,const char * argv[],int * Icode,struct IA_FIpar FI[MAXFILE],int * Nfiles)48 IAoptions (int argc, const char *argv[], int *Icode,
49 struct IA_FIpar FI[MAXFILE], int *Nfiles)
50
51 {
52 struct IA_FIpar FIx;
53 int n, nF, icode, FIParSet;
54 const char *OptArg;
55
56 /* Default values */
57 FIParSet = 0;
58 FIpar_INIT (&FIx);
59
60 icode = 7;
61
62 /* Initialization */
63 UTsetProg (PROGRAM);
64 nF = 0;
65
66 /* Decode options */
67 AOinitOpt (argc, argv);
68 while (1) {
69
70 /* Decode input file options */
71 n = AOdecFI (&FIx);
72 if (n >= 1) {
73 FIParSet = nF;
74 continue;
75 }
76
77 /* Decode help options */
78 n = AOdecHelp (VERSION, IAMF_Usage);
79 if (n >= 1)
80 continue;
81
82 /* Decode program options */
83 n = AOdecOpt (OptTable, &OptArg);
84 if (n == -1)
85 break;
86
87 switch (n) {
88 case -2:
89 UThalt (IAMF_Usage, PROGRAM);
90 break;
91 case 0:
92 /* Filename argument */
93 ++nF;
94 if (nF > MAXFILE)
95 UThalt ("%s: %s", PROGRAM, IAM_XFName);
96 STcopyMax (OptArg, FIx.Fname, FILENAME_MAX-1);
97 FI[nF-1] = FIx;
98 break;
99 case 1:
100 case 2:
101 /* Info code parameter */
102 if (STdec1int (OptArg, &icode) || icode < 0 || icode > 7)
103 ERRSTOP (IAM_BadInfoCode, OptArg);
104 break;
105 default:
106 assert (0);
107 break;
108 }
109 }
110
111 /* Error checks */
112 if (nF <= 0)
113 UThalt ("%s: %s", PROGRAM, IAM_NoFName);
114 if (FIParSet >= nF)
115 UThalt ("%s: %s", PROGRAM, IAM_LateFPar);
116
117 /* Check for too many stdin specs */
118 AOstdin (FI, nF);
119
120 /* Return parameter */
121 *Icode = icode;
122 *Nfiles = nF;
123
124 return;
125 }
126