|
|
1.1 root 1: /* cmdarg.c
2: Look up a command with arguments in a command table.
3:
4: Copyright (C) 1992 Ian Lance Taylor
5:
6: This file is part of the Taylor UUCP uuconf library.
7:
8: This library is free software; you can redistribute it and/or
9: modify it under the terms of the GNU Library General Public License
10: as published by the Free Software Foundation; either version 2 of
11: the License, or (at your option) any later version.
12:
13: This library is distributed in the hope that it will be useful, but
14: WITHOUT ANY WARRANTY; without even the implied warranty of
15: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16: Library General Public License for more details.
17:
18: You should have received a copy of the GNU Library General Public
19: License along with this library; if not, write to the Free Software
20: Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21:
22: The author of the program may be contacted at [email protected] or
23: c/o Infinity Development Systems, P.O. Box 520, Waltham, MA 02254.
24: */
25:
26: #include "uucnfi.h"
27:
28: #if USE_RCS_ID
29: const char _uuconf_cmdarg_rcsid[] = "$Id: cmdarg.c,v 1.1 93/07/30 08:07:04 bin Exp Locker: bin $";
30: #endif
31:
32: #include <ctype.h>
33:
34: #undef strcmp
35: #if HAVE_STRCASECMP
36: #undef strcasecmp
37: #endif
38: extern int strcmp (), strcasecmp ();
39:
40: /* Look up a command with arguments in a table and execute it. */
41:
42: int
43: uuconf_cmd_args (pglobal, cargs, pzargs, qtab, pinfo, pfiunknown, iflags,
44: pblock)
45: pointer pglobal;
46: int cargs;
47: char **pzargs;
48: const struct uuconf_cmdtab *qtab;
49: pointer pinfo;
50: int (*pfiunknown) P((pointer, int, char **, pointer, pointer));
51: int iflags;
52: pointer pblock;
53: {
54: struct sglobal *qglobal = (struct sglobal *) pglobal;
55: int bfirstu, bfirstl;
56: int (*pficmp) P((const char *, const char *));
57: register const struct uuconf_cmdtab *q;
58: int itype;
59: int callowed;
60:
61: bfirstu = bfirstl = pzargs[0][0];
62: if ((iflags & UUCONF_CMDTABFLAG_CASE) != 0)
63: pficmp = strcmp;
64: else
65: {
66: if (islower (bfirstu))
67: bfirstu = toupper (bfirstu);
68: if (isupper (bfirstl))
69: bfirstl = tolower (bfirstl);
70: pficmp = strcasecmp;
71: }
72:
73: itype = 0;
74:
75: for (q = qtab; q->uuconf_zcmd != NULL; q++)
76: {
77: int bfirst;
78:
79: bfirst = q->uuconf_zcmd[0];
80: if (bfirst != bfirstu && bfirst != bfirstl)
81: continue;
82:
83: itype = UUCONF_TTYPE_CMDTABTYPE (q->uuconf_itype);
84: if (itype != UUCONF_CMDTABTYPE_PREFIX)
85: {
86: if ((*pficmp) (q->uuconf_zcmd, pzargs[0]) == 0)
87: break;
88: }
89: else
90: {
91: size_t clen;
92:
93: clen = strlen (q->uuconf_zcmd);
94: if ((iflags & UUCONF_CMDTABFLAG_CASE) != 0)
95: {
96: if (strncmp (q->uuconf_zcmd, pzargs[0], clen) == 0)
97: break;
98: }
99: else
100: {
101: if (strncasecmp (q->uuconf_zcmd, pzargs[0], clen) == 0)
102: break;
103: }
104: }
105: }
106:
107: if (q->uuconf_zcmd == NULL)
108: {
109: if (pfiunknown == NULL)
110: return UUCONF_CMDTABRET_CONTINUE;
111: return (*pfiunknown) (pglobal, cargs, pzargs, (pointer) NULL, pinfo);
112: }
113:
114: callowed = UUCONF_CARGS_CMDTABTYPE (q->uuconf_itype);
115: if (callowed != 0 && callowed != cargs)
116: return UUCONF_SYNTAX_ERROR | UUCONF_CMDTABRET_EXIT;
117:
118: switch (itype)
119: {
120: case UUCONF_TTYPE_CMDTABTYPE (UUCONF_CMDTABTYPE_STRING):
121: if (cargs == 1)
122: *(char **) q->uuconf_pvar = (char *) "";
123: else if (cargs == 2)
124: *(char **) q->uuconf_pvar = pzargs[1];
125: else
126: return UUCONF_SYNTAX_ERROR | UUCONF_CMDTABRET_EXIT;
127:
128: return UUCONF_CMDTABRET_KEEP;
129:
130: case UUCONF_TTYPE_CMDTABTYPE (UUCONF_CMDTABTYPE_INT):
131: return _uuconf_iint (qglobal, pzargs[1], q->uuconf_pvar, TRUE);
132:
133: case UUCONF_TTYPE_CMDTABTYPE (UUCONF_CMDTABTYPE_LONG):
134: return _uuconf_iint (qglobal, pzargs[1], q->uuconf_pvar, FALSE);
135:
136: case UUCONF_TTYPE_CMDTABTYPE (UUCONF_CMDTABTYPE_BOOLEAN):
137: return _uuconf_iboolean (qglobal, pzargs[1], (int *) q->uuconf_pvar);
138:
139: case UUCONF_TTYPE_CMDTABTYPE (UUCONF_CMDTABTYPE_FULLSTRING):
140: if (cargs == 1)
141: {
142: char ***ppz = (char ***) q->uuconf_pvar;
143: int iret;
144:
145: *ppz = NULL;
146: iret = _uuconf_iadd_string (qglobal, (char *) NULL, FALSE, FALSE,
147: ppz, pblock);
148: if (iret != UUCONF_SUCCESS)
149: return iret | UUCONF_CMDTABRET_EXIT;
150:
151: return UUCONF_CMDTABRET_CONTINUE;
152: }
153: else
154: {
155: char ***ppz = (char ***) q->uuconf_pvar;
156: int i;
157:
158: *ppz = NULL;
159: for (i = 1; i < cargs; i++)
160: {
161: int iret;
162:
163: iret = _uuconf_iadd_string (qglobal, pzargs[i], FALSE, FALSE,
164: ppz, pblock);
165: if (iret != UUCONF_SUCCESS)
166: {
167: *ppz = NULL;
168: return iret | UUCONF_CMDTABRET_EXIT;
169: }
170: }
171:
172: return UUCONF_CMDTABRET_KEEP;
173: }
174:
175: case UUCONF_TTYPE_CMDTABTYPE (UUCONF_CMDTABTYPE_FN):
176: case UUCONF_TTYPE_CMDTABTYPE (UUCONF_CMDTABTYPE_PREFIX):
177: return (*q->uuconf_pifn) (pglobal, cargs, pzargs, q->uuconf_pvar,
178: pinfo);
179:
180: default:
181: return UUCONF_SYNTAX_ERROR | UUCONF_CMDTABRET_EXIT;
182: }
183:
184: /*NOTREACHED*/
185: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.