X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/mLib/blobdiff_plain/4ce6f42e899799bff22c1378deaa4a1a7ece7e91..d4efbcd93c940ad522fcf8c601ec1829d2e0b10d:/traceopt.c diff --git a/traceopt.c b/traceopt.c index 08cdd57..2d1594f 100644 --- a/traceopt.c +++ b/traceopt.c @@ -1,13 +1,13 @@ /* -*-c-*- * - * $Id: traceopt.c,v 1.1 1999/10/22 22:40:08 mdw Exp $ + * $Id: traceopt.c,v 1.3 2004/04/08 01:36:13 mdw Exp $ * * Parsing tracing options * * (c) 1999 Straylight/Edgeware */ -/*----- Licensing notice --------------------------------------------------* +/*----- Licensing notice --------------------------------------------------* * * This file is part of the mLib utilities library. * @@ -15,26 +15,18 @@ * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. - * + * * mLib is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details. - * + * * You should have received a copy of the GNU Library General Public * License along with mLib; if not, write to the Free * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, * MA 02111-1307, USA. */ -/*----- Revision history --------------------------------------------------* - * - * $Log: traceopt.c,v $ - * Revision 1.1 1999/10/22 22:40:08 mdw - * Separate function for parsing user trace specs. - * - */ - /*----- Header files ------------------------------------------------------*/ #include @@ -48,7 +40,7 @@ /* --- @traceopt@ --- * * - * Arguments: @trace_opt *t@ = pointer to trace options table + * Arguments: @const trace_opt *t@ = pointer to trace options table * @const char *p@ = option string supplied by user * @unsigned f@ = initial tracing flags * @unsigned bad@ = forbidden tracing flags @@ -60,18 +52,20 @@ * `?' character, a help message is displayed. */ -unsigned traceopt(trace_opt *t, const char *p, unsigned f, unsigned bad) +unsigned traceopt(const trace_opt *t, const char *p, + unsigned f, unsigned bad) { unsigned sense = 1; /* --- Dump out help text --- */ - if (!p || strcmp(p, "?")) { + if (!p || !strcmp(p, "?")) { + const trace_opt *tt; puts("Trace options:"); - while (t->ch) { - if (t->f & bad || !t->help) + for (tt = t; tt->ch; tt++) { + if (!(tt->f & ~bad) || !tt->help) continue; - printf(" `%c': %s\n", t->ch, t->help); + printf(" `%c': %s\n", tt->ch, tt->help); } return (f); } @@ -88,17 +82,17 @@ unsigned traceopt(trace_opt *t, const char *p, unsigned f, unsigned bad) sense = 0; break; default: { - trace_opt *tt; + const trace_opt *tt; for (tt = t; tt->ch; tt++) { - if (tt->f & bad) + if (!(tt->f & ~bad)) continue; if (tt->ch == *p) { if (sense) f |= (tt->f & ~bad); else f &= ~(tt->f & ~bad); + goto ok; } - goto ok; } moan("unknown trace option `%c'", *p); ok:;