1 /*------------- Telecommunications & Signal Processing Lab -------------
2                            McGill University
3 
4 Routine:
5   void AOinitOpt (const int argc, const char *argv[])
6   int AOdecOpt (const char *OptTable[], const char **OptArg)
7   struct AO_CmdArg *AOArgs (void)
8 
9 Purpose:
10   Decode options for audio utilities
11 
12 Description:
13   These routines decode options for audio utilties.  The routine AOinitOpt is
14   used to initialize the argument array.  The routine AOdecOpt decodes options
15   using a user supplied option table
16 
17 Parameters:
18   void AOinitOpt
19    -> int argc
20       Number of command line arguments
21    -> const char *argv[]
22       Array of pointers to argument strings
23 
24   <-  int  AOdecOpt
25       Status code,
26          -2 - Error, invalid option or missing value
27          -1 - End of arguments/options
28           0 - Not an option, argument is returned
29         >=1 - Option code
30    -> const char *OptTable[]
31       Pointers to the option keywords.  The end of the keyword table is
32       signalled by a NULL pointer.  These keyword strings are pased to
33       UTgetOption.
34   <-  const char *OptArg[]
35       Argument/option string.  For an argument or an option taking a value,
36       this is a pointer to a null terminated substring string in argv.  If the
37       decoded option does not take a value, this pointer will be NULL.
38 
39 Author / revision:
40   P. Kabal  Copyright (C) 2003
41   $Revision: 1.11 $  $Date: 2003/05/09 12:32:37 $
42 
43 ----------------------------------------------------------------------*/
44 
45 #include <libtsp.h>
46 #include <AObase.h>
47 
48 static const char *nullTable[] = { NULL };
49 
50 /* Initialize the command line argument structure */
51 static struct AO_CmdArg AOArg = {NULL, 0, 1, 0};
52 
53 
54 void
AOinitOpt(const int argc,const char * argv[])55 AOinitOpt (const int argc, const char *argv[])
56 
57 {
58 /* Set the argument pointer structure */
59   AOArg.Argv = argv;
60   AOArg.Argc = argc;
61   AOArg.Index = 1;
62   AOArg.EndOptions = 0;
63 
64   return;
65 }
66 
67 /* Return a pointer to the argument pointer structure */
68 
69 
70 struct AO_CmdArg *
AOArgs(void)71 AOArgs (void)
72 
73 {
74   return &AOArg;
75 }
76 
77 /* Decode user options */
78 
79 
80 int
AOdecOpt(const char * OptTable[],const char ** OptArg)81 AOdecOpt (const char *OptTable[], const char **OptArg)
82 
83 {
84   int n;
85   struct AO_CmdArg *Carg;
86 
87   /* Get the argument pointers */
88   Carg = AOArgs ();
89 
90   /* Decode the option */
91   if (Carg->EndOptions)
92     n = UTgetOption (&Carg->Index, Carg->Argc, Carg->Argv, nullTable, OptArg);
93   else
94     n = UTgetOption (&Carg->Index, Carg->Argc, Carg->Argv, OptTable, OptArg);
95 
96   return n;
97 }
98