1 /* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23 #include "glk/tads/tads2/command_line.h"
24
25 namespace Glk {
26 namespace TADS {
27 namespace TADS2 {
28
29 /* get a toggle argument */
cmdtog(errcxdef * ec,int prv,char * argp,int ofs,void (* usagefn)(errcxdef *))30 int cmdtog(errcxdef *ec, int prv, char *argp, int ofs,
31 void (*usagefn)(errcxdef *))
32 {
33 switch(argp[ofs + 1])
34 {
35 case '+':
36 return(TRUE);
37
38 case '-':
39 return(FALSE);
40
41 case '\0':
42 return(!prv);
43
44 default:
45 /* invalid - display usage if we have a callback for it */
46 if (usagefn != 0)
47 (*usagefn)(ec);
48 NOTREACHEDV(int);
49 return 0;
50 }
51 }
52
53 /* get an argument to a switch */
cmdarg(errcxdef * ec,char *** argpp,int * ip,int argc,int ofs,void (* usagefn)(errcxdef *))54 char *cmdarg(errcxdef *ec, char ***argpp, int *ip, int argc, int ofs,
55 void (*usagefn)(errcxdef *))
56 {
57 char *ret;
58
59 /*
60 * check to see if the argument is appended directly to the option;
61 * if not, look at the next string
62 */
63 ret = (**argpp) + ofs + 1;
64 if (*ret == '\0')
65 {
66 /*
67 * it's not part of this string - get the argument from the next
68 * string in the vector
69 */
70 ++(*ip);
71 ++(*argpp);
72 ret = (*ip >= argc ? 0 : **argpp);
73 }
74
75 /*
76 * if we didn't find the argument, it's an error - display usage if
77 * we have a valid usage callback
78 */
79 if ((ret == 0 || *ret == 0) && usagefn != 0)
80 (*usagefn)(ec);
81
82 return ret;
83 }
84
85 } // End of namespace TADS2
86 } // End of namespace TADS
87 } // End of namespace Glk
88