2 dnl lexer, passed through m4 with defs from langauge.i4
4 * Copyright (C)1996-1997 Ian Jackson
6 * This is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with userv; if not, write to the Free Software
18 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
47 typedef int directive_fnt(int dtoken);
48 static directive_fnt df_reject, df_execute, df_executefrompath;
49 static directive_fnt df_executefromdirectory;
50 static directive_fnt df_errorstostderr, df_errorstosyslog, df_errorstofile;
51 static directive_fnt dfg_fdwant, dfg_setflag;
52 static directive_fnt df_reset, df_cd, df_userrcfile, df_include;
53 static directive_fnt df_includelookup, df_includedirectory;
54 static directive_fnt df_message, df_error, df_quit, df_eof;
55 static directive_fnt df_if, df_catchquit, df_errorspush;
56 static directive_fnt dfi_includeuserrcfile, dfi_includeclientconfig;
57 /* directive functions return:
58 * 0 for success having scanned up to and including end of line but not beyond,
59 * or tokv_error or tokv_quit.
62 typedef int parmcondition_fnt(int ctoken, char **parmvalues, int *rtrue);
63 static parmcondition_fnt pcf_glob, pcf_range, pcf_grep;
64 /* all conditional functions return tokv_error for failure or 0 for success
65 * at parsing and testing, in which case *rtrue is set to 0 or 1.
66 * On success they have scanned up to and including the condition's
67 * terminating newline.
68 * The parameter-based conditionals take a list of parameter values
69 * as obtained from the parameter functions and pa_parameter,
70 * and do _not_ free it.
73 typedef int parameter_fnt(int ptoken, char ***rvalues);
74 static parameter_fnt pf_service;
75 static parameter_fnt pf_callinguser, pf_serviceuser;
76 static parameter_fnt pf_callinggroup, pf_servicegroup;
77 static parameter_fnt pf_callingusershell, pf_serviceusershell;
78 /* Parameter functions return tokv_error or 0 for success at parsing
79 * and determining the value, in which case *rvalues is made to be
80 * a mallocd null-terminated array of pointers to mallocd strings.
81 * freeparm can be used to free such an array.
84 static int yylex(void);
85 /* Returns a token (which may be an eof or error exception) */
87 static directive_fnt *lr_dir;
88 static parmcondition_fnt *lr_parmcond;
89 static parameter_fnt *lr_parameter;
90 static int lr_loglevel, lr_logfacility, lr_min, lr_max, *lr_flag;
91 static int lr_flagval, lr_controlend;
92 static int lr_fdwant_readwrite; /* -1=never, 0=opt, 1=always */
94 /* Forward declarations of things used in lexer and parser */
97 int lineno, reportlineno, notedreferer, isinternal;
100 struct parser_state *upstate;
103 static struct parser_state *cstate;
105 struct error_handling {
106 int handling; /* One of the error handling modes tokt_ehandlemode */
107 int logfacility, loglevel, filekeep;
112 static struct error_handling eh = { tokv_word_errorstostderr, 0,0,0,0,0 };
114 static int dequote(char *inplace);
126 lr_min=lr_max= (int)strtoul(yytext,&ep,10);
130 [0-9]{1,8}-[0-9]{1,8} {
132 lr_min=(int)strtoul(yytext,&ep,10);
133 assert(*ep == HYPHEN);
135 lr_max=(int)strtoul(ep,&ep,10);
137 if (lr_max < lr_min) {
138 parseerrprint("fd range has min > max");
145 lr_min= (int)strtoul(yytext,&ep,10);
146 assert(*ep == HYPHEN);
149 return tokv_fdstoend;
151 [\ \t]+ return tokv_lwsp;
152 [\ \t]*\n cstate->lineno++; return tokv_newline;
153 [\ \t]*\#[^\n]*\n cstate->lineno++; return tokv_newline;
155 parseerrprint("missing newline at eof after comment");
158 [^\ \t\n]+ return tokv_barestring;
159 \"([^\\\"\n]|\\[a-z]|\\[0-9]{3}|\\x[0-9A-Fa-f]{2}|\\[:punct:]|\\[ \t]*\n)*\" {
160 return dequote(yytext);
163 parseerrprint("misquoted or unterminated string");
166 <<EOF>> return tokv_eof;