From e73034b0d2191f00a8b00f38383843ea8858c576 Mon Sep 17 00:00:00 2001 From: mdw Date: Thu, 19 Aug 1999 18:32:48 +0000 Subject: [PATCH] Improve lexical analysis. In particular, `chmod' patterns don't have to be quoted any more. --- conf.c | 34 ++++++++++++++++++++++++++++------ conf.h | 19 ++++++++++++++++++- fattr.c | 35 +++++++++++++++++++++-------------- fw.1 | 15 ++++++++------- 4 files changed, 75 insertions(+), 28 deletions(-) diff --git a/conf.c b/conf.c index 020df7a..73b611f 100644 --- a/conf.c +++ b/conf.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: conf.c,v 1.2 1999/07/26 23:28:39 mdw Exp $ + * $Id: conf.c,v 1.3 1999/08/19 18:32:48 mdw Exp $ * * Configuration parsing * @@ -29,6 +29,10 @@ /*----- Revision history --------------------------------------------------* * * $Log: conf.c,v $ + * Revision 1.3 1999/08/19 18:32:48 mdw + * Improve lexical analysis. In particular, `chmod' patterns don't have to + * be quoted any more. + * * Revision 1.2 1999/07/26 23:28:39 mdw * Major reconstruction work for new design. * @@ -66,8 +70,24 @@ static source_ops *sources[] = { &xsource_ops, &fsource_ops, &ssource_ops }; static target_ops *targets[] = { &xtarget_ops, &ftarget_ops, &starget_ops }; +static const char *notword = 0; +static const char *notdelim = 0; + /*----- Main code ---------------------------------------------------------*/ +/* --- @undelim@ --- * + * + * Arguments: @const char *d, dd@ = pointer to characters to escape + * + * Returns: --- + * + * Use: Modifies the tokenizer. Characters in the first list will + * always be considered to begin a word. Characters in the + * second list will always be allowed to continue a word. + */ + +void undelim(const char *d, const char *dd) { notword = d; notdelim = dd; } + /* --- @token@ --- * * * Arguments: @scanner *sc@ = pointer to scanner definition @@ -122,10 +142,12 @@ int token(scanner *sc) /* --- Various self-delimiting characters --- */ case SELFDELIM: - dstr_putc(&sc->d, ch); - dstr_putz(&sc->d); - sc->t = ch; - goto done; + if (!notword || strchr(notword, ch) == 0) { + dstr_putc(&sc->d, ch); + dstr_putz(&sc->d); + sc->t = ch; + goto done; + } /* --- Bare words --- * * @@ -150,7 +172,7 @@ int token(scanner *sc) q = !q; break; case SELFDELIM: - if (q) + if (q || (notdelim && strchr(notdelim, ch))) goto insert; goto word; default: diff --git a/conf.h b/conf.h index 6183048..e0eddf8 100644 --- a/conf.h +++ b/conf.h @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: conf.h,v 1.3 1999/07/27 18:30:14 mdw Exp $ + * $Id: conf.h,v 1.4 1999/08/19 18:32:48 mdw Exp $ * * Configuration parsing * @@ -29,6 +29,10 @@ /*----- Revision history --------------------------------------------------* * * $Log: conf.h,v $ + * Revision 1.4 1999/08/19 18:32:48 mdw + * Improve lexical analysis. In particular, `chmod' patterns don't have to + * be quoted any more. + * * Revision 1.3 1999/07/27 18:30:14 mdw * Improve documentation and layout for @CONF_BEGIN@ and friends. Remove * irritating warning about unused label by introducing a spurious `goto'. @@ -63,6 +67,19 @@ /*----- Functions provided ------------------------------------------------*/ +/* --- @undelim@ --- * + * + * Arguments: @const char *d, dd@ = pointer to characters to escape + * + * Returns: --- + * + * Use: Modifies the tokenizer. Characters in the first list will + * always be considered to begin a word. Characters in the + * second list will always be allowed to continue a word. + */ + +extern void undelim(const char */*d*/, const char */*dd*/); + /* --- @token@ --- * * * Arguments: @scanner *sc@ = pointer to scanner definition diff --git a/fattr.c b/fattr.c index 0406a11..75491a6 100644 --- a/fattr.c +++ b/fattr.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: fattr.c,v 1.1 1999/07/26 23:33:56 mdw Exp $ + * $Id: fattr.c,v 1.2 1999/08/19 18:32:48 mdw Exp $ * * Handling of file attributes * @@ -29,6 +29,10 @@ /*----- Revision history --------------------------------------------------* * * $Log: fattr.c,v $ + * Revision 1.2 1999/08/19 18:32:48 mdw + * Improve lexical analysis. In particular, `chmod' patterns don't have to + * be quoted any more. + * * Revision 1.1 1999/07/26 23:33:56 mdw * Support code for new design. * @@ -100,12 +104,14 @@ int fattr_option(scanner *sc, fattr *f) /* --- Gobble an optional `=' sign --- */ + undelim(0, ",=+-"); token(sc); if (sc->t == '=') token(sc); if (sc->t != CTOK_WORD) error(sc, "parse error, expected file mode"); + undelim(0, 0); /* --- If it looks digitlike, read as octal --- */ @@ -116,7 +122,8 @@ int fattr_option(scanner *sc, fattr *f) else { const char *p; - unsigned mask = 07777; + unsigned mask = 04700; + unsigned state = 0; unsigned or = 1; /* --- Set the default from the umask --- */ @@ -137,21 +144,21 @@ int fattr_option(scanner *sc, fattr *f) switch (*p) { case ',': break; - case 'a': mask = 07777; break; - case 'u': mask = 04700; break; - case 'g': mask = 02070; break; - case 'o': mask = 01007; break; + case 'a': mask = (mask & state) | 07777; state = 07777; break; + case 'u': mask = (mask & state) | 04700; state = 07777; break; + case 'g': mask = (mask & state) | 02070; state = 07777; break; + case 'o': mask = (mask & state) | 01007; state = 07777; break; - case '=': mode &= ~mask; break; - case '-': or = 0; break; - case '+': or = 1; break; + case '=': mode &= ~mask; /* Drop through */ + case '+': state = 0; or = 1; break; + case '-': state = 0; or = 0; break; #define APPLY(m) if (or) mode |= ((m) & mask); else mode &= ~((m) & mask); - case 'r': APPLY(00444); break; - case 'w': APPLY(00222); break; - case 'x': APPLY(00111); break; - case 's': APPLY(06000); break; - case 't': APPLY(01000); break; + case 'r': state = 0; APPLY(00444); break; + case 'w': state = 0; APPLY(00222); break; + case 'x': state = 0; APPLY(00111); break; + case 's': state = 0; APPLY(06000); break; + case 't': state = 0; APPLY(01000); break; #undef APPLY default: error(sc, "unknown mode character `%c'", *p); diff --git a/fw.1 b/fw.1 index c65c6c0..6cd0c64 100644 --- a/fw.1 +++ b/fw.1 @@ -1,6 +1,6 @@ .\" -*-nroff-*- .\" -.\" $Id: fw.1,v 1.3 1999/07/30 06:49:00 mdw Exp $ +.\" $Id: fw.1,v 1.4 1999/08/19 18:32:48 mdw Exp $ .\" .\" Manual page for fw .\" @@ -28,6 +28,10 @@ .\" ---- Revision history --------------------------------------------------- .\" .\" $Log: fw.1,v $ +.\" Revision 1.4 1999/08/19 18:32:48 mdw +.\" Improve lexical analysis. In particular, `chmod' patterns don't have to +.\" be quoted any more. +.\" .\" Revision 1.3 1999/07/30 06:49:00 mdw .\" Minor tidying and typo correction. .\" @@ -482,7 +486,7 @@ sources and targets is like this: .br .I null-spec ::= -.RB [[ : ] null [ : ]] +.RB [ : ] null [ : ] .PP The .I file @@ -603,14 +607,11 @@ argument may be either an octal number or a string which acts on the default permissions established by the prevailing .BR umask (2) -setting. Note that -.BR chmod -style -strings may contain +setting. The characters .RB ` = ' and .RB ` , ' -characters that will need to be escaped or quoted. -.RE +do not have to be quoted within the mode string. .PP .IB prefix .fattr.owner .RB [ = ] -- 2.11.0