Debian Codegraph @

terps/tads/tads2/cmd.c

raw symbols SCIP
1 #ifdef RCSID
2 static char RCSid[] =
3 "$Header: d:/cvsroot/tads/TADS2/CMD.C,v 1.2 1999/05/17 02:52:11 MJRoberts Exp $";
4 #endif
5
6 /*
7 * Copyright (c) 1992, 2002 Michael J. Roberts. All Rights Reserved.
8 *
9 * Please see the accompanying license file, LICENSE.TXT, for information
10 * on using and copying this software.
11 */
12 /*
13 Name
14 cmd.c - command line option reader
15 Function
16 service functions for interpreting command line options
17 Notes
18 none
19 Modified
20 04/04/92 MJRoberts - creation
21 */
22
23 #include "os.h"
24 #include "std.h"
25 #include "err.h"
26 #include "cmd.h"
27
28 /* get a toggle argument */
29 int cmdtog(errcxdef *ec, int prv, char *argp, int ofs,
30 void (*usagefn)(errcxdef *))
31 {
32 switch(argp[ofs + 1])
33 {
34 case '+':
35 return(TRUE);
36
37 case '-':
38 return(FALSE);
39
40 case '\0':
41 return(!prv);
42
43 default:
44 /* invalid - display usage if we have a callback for it */
45 if (usagefn != 0)
46 (*usagefn)(ec);
47 NOTREACHEDV(int);
48 return 0;
49 }
50 }
51
52 /* get an argument to a switch */
53 char *cmdarg(errcxdef *ec, char ***argpp, int *ip, int argc, int ofs,
54 void (*usagefn)(errcxdef *))
55 {
56 char *ret;
57
58 /*
59 * check to see if the argument is appended directly to the option;
60 * if not, look at the next string
61 */
62 ret = (**argpp) + ofs + 1;
63 if (*ret == '\0')
64 {
65 /*
66 * it's not part of this string - get the argument from the next
67 * string in the vector
68 */
69 ++(*ip);
70 ++(*argpp);
71 ret = (*ip >= argc ? 0 : **argpp);
72 }
73
74 /*
75 * if we didn't find the argument, it's an error - display usage if
76 * we have a valid usage callback
77 */
78 if ((ret == 0 || *ret == 0) && usagefn != 0)
79 (*usagefn)(ec);
80
81 return ret;
82 }
83