X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=blobdiff_plain;ds=inline;f=lexer.l.m4;h=5aaeff088b312349b22732ce2ce0bca3738731a4;hb=7bc3c582a0a80d34d2c9c86ed9a588b3983e0db1;hp=0337686c72827a52541d05fdfa6d320262423b23;hpb=9f56f874416db295bdb50d448bd99cdd34db969d;p=userv.git diff --git a/lexer.l.m4 b/lexer.l.m4 index 0337686..5aaeff0 100644 --- a/lexer.l.m4 +++ b/lexer.l.m4 @@ -33,8 +33,10 @@ include(language.i4) #include #include #include +#include #include #include +#include #include "config.h" #include "common.h" @@ -46,7 +48,7 @@ include(language.i4) typedef int directive_fnt(int dtoken); static directive_fnt df_reject, df_execute, df_executefrompath; -static directive_fnt df_executefromdirectory; +static directive_fnt df_executefromdirectory, df_executebuiltin; static directive_fnt df_errorstostderr, df_errorstosyslog, df_errorstofile; static directive_fnt dfg_fdwant, dfg_setflag; static directive_fnt df_reset, df_cd, df_userrcfile, df_include; @@ -57,14 +59,17 @@ static directive_fnt dfi_includeuserrcfile, dfi_includeclientconfig; /* directive functions return: * 0 for success having scanned up to and including end of line but not beyond, * or tokv_error or tokv_quit. + * They expect to parse the whitespace before their parameters (if any). */ -typedef int parmcondition_fnt(int ctoken, char **parmvalues, int *rtrue); +typedef int parmcondition_fnt(int ctoken, char *const *parmvalues, int *rtrue); static parmcondition_fnt pcf_glob, pcf_range, pcf_grep; /* all conditional functions return tokv_error for failure or 0 for success * at parsing and testing, in which case *rtrue is set to 0 or 1. * On success they have scanned up to and including the condition's - * terminating newline. + * terminating newline; the pcf_... functions expect to parse the whitespace + * between the parameter name and the condition's arguments. + * Otherwise they return tokv_error. * The parameter-based conditionals take a list of parameter values * as obtained from the parameter functions and pa_parameter, * and do _not_ free it. @@ -81,11 +86,23 @@ static parameter_fnt pf_callingusershell, pf_serviceusershell; * freeparm can be used to free such an array. */ +typedef int builtinserviceparse_fnt(char ***rnewargs); +static builtinserviceparse_fnt bispa_none, bispa_parameter; +/* These parse the arguments to a builtin service, including the + * newline at the end of the line. *rnewargs will initially be + * null, indicating that no arguments are to be set; the function + * may store a mallocd array of mallocd strings in it, + * containing the arguments it wishes to have set (null-pointer + * terminated). + */ + static int yylex(void); /* Returns a token (which may be an eof or error exception) */ static directive_fnt *lr_dir; static parmcondition_fnt *lr_parmcond; +static builtinserviceparse_fnt *lr_bispa; +static builtinserviceexec_fnt *lr_bisexec; static parameter_fnt *lr_parameter; static int lr_loglevel, lr_logfacility, lr_min, lr_max, *lr_flag; static int lr_flagval, lr_controlend; @@ -96,6 +113,7 @@ static int lr_fdwant_readwrite; /* -1=never, 0=opt, 1=always */ struct parser_state { int lineno, reportlineno, notedreferer, isinternal; const char *filename; + struct stat filestab; YY_BUFFER_STATE ybuf; struct parser_state *upstate; }; @@ -104,7 +122,8 @@ static struct parser_state *cstate; struct error_handling { int handling; /* One of the error handling modes tokt_ehandlemode */ - int logfacility, loglevel, filekeep; + int logfacility, loglevel; + int filekeep; /* File is in use by higher-level errors-push, leave it open */ FILE *file; char *filename; }; @@ -113,8 +132,12 @@ static struct error_handling eh = { tokv_word_errorstostderr, 0,0,0,0,0 }; static int dequote(char *inplace); +#define YY_NO_UNPUT + %} + %option noyywrap + %% dnl simple words @@ -129,10 +152,10 @@ changequote({*,*}) } [0-9]{1,8}-[0-9]{1,8} { char *ep; - lr_min=(int)strtoul(yytext,&ep,10); + lr_min= (int)strtoul(yytext,&ep,10); assert(*ep == HYPHEN); assert(*++ep); - lr_max=(int)strtoul(ep,&ep,10); + lr_max= (int)strtoul(ep,&ep,10); assert(!*ep); if (lr_max < lr_min) { parseerrprint("fd range has min > max"); @@ -155,14 +178,14 @@ changequote({*,*}) parseerrprint("missing newline at eof after comment"); return tokv_error; } -[^\ \t\n]+ return tokv_barestring; -\"([^\\\"\n]|\\[a-z]|\\[0-9]{3}|\\x[0-9A-Fa-f]{2}|\\[:punct:]|\\[ \t]*\n)*\" { +\"([^\\\"\n]|\\[a-z]|\\[0-9]{3}|\\x[0-9A-Fa-f]{2}|\\[[:punct:]]|\\[ \t]*\n)*\" { return dequote(yytext); } \".* { parseerrprint("misquoted or unterminated string"); return tokv_error; } +[^\ \t\n]+ return tokv_barestring; <> return tokv_eof; *} changequote(`,') @@ -172,4 +195,3 @@ changequote(`,') ' divert(-1) undivert -