From ca6e3cb0e42e2e614156bf6d57be193df93deda7 Mon Sep 17 00:00:00 2001 From: Kelly Yancey Date: Mon, 23 Dec 2002 20:08:21 +0000 Subject: [PATCH] Make preprocessor support more generic by passing all command-line options after -p except for the last (the ruleset file to process) to the preprocessor for interpretation. This allows command-line options besides -U and -D to be passed to cpp(1) and m4(1) as well as making it easier to use other preprocessors. Sponsored By: NTT Multimedia Communications Labs MFC after: 1 week --- sbin/ipfw/ipfw.8 | 12 ++++-------- sbin/ipfw/ipfw.c | 35 ++++++++++++++--------------------- sbin/ipfw/ipfw2.c | 35 ++++++++++++++--------------------- 3 files changed, 32 insertions(+), 50 deletions(-) diff --git a/sbin/ipfw/ipfw.8 b/sbin/ipfw/ipfw.8 index 7fb82725ede4..1d07fcdb5084 100644 --- a/sbin/ipfw/ipfw.8 +++ b/sbin/ipfw/ipfw.8 @@ -51,10 +51,9 @@ .Op Fl q .Oo .Fl p Ar preproc -.Oo Fl D -.Ar macro Ns Op = Ns Ar value +.Oo +.Ar preproc-flags .Oc -.Op Fl U Ar macro .Oc .Ar pathname .Sh DESCRIPTION @@ -289,11 +288,8 @@ file systems are mounted (yet) by the time is being run (e.g. when they are mounted over NFS). Once .Fl p -has been specified, optional -.Fl D -and -.Fl U -specifications can follow and will be passed on to the preprocessor. +has been specified, any additional arguments as passed on to the preprocessor +for interpretation. This allows for flexible configuration files (like conditionalizing them on the local hostname) and the use of macros to centralize frequently required arguments like IP addresses. diff --git a/sbin/ipfw/ipfw.c b/sbin/ipfw/ipfw.c index c4f00fd756d6..740aba8297eb 100644 --- a/sbin/ipfw/ipfw.c +++ b/sbin/ipfw/ipfw.c @@ -2529,28 +2529,8 @@ ipfw_readfile(int ac, char *av[]) pid_t preproc = 0; int c; - while ((c = getopt(ac, av, "D:U:p:q")) != -1) + while ((c = getopt(ac, av, "p:q")) != -1) { switch(c) { - case 'D': - if (!pflag) - errx(EX_USAGE, "-D requires -p"); - if (i > MAX_ARGS - 2) - errx(EX_USAGE, - "too many -D or -U options"); - args[i++] = "-D"; - args[i++] = optarg; - break; - - case 'U': - if (!pflag) - errx(EX_USAGE, "-U requires -p"); - if (i > MAX_ARGS - 2) - errx(EX_USAGE, - "too many -D or -U options"); - args[i++] = "-U"; - args[i++] = optarg; - break; - case 'p': pflag = 1; cmd = optarg; @@ -2567,6 +2547,19 @@ ipfw_readfile(int ac, char *av[]) " summary ``ipfw''"); } + if (pflag) + break; + } + + if (pflag) { + /* Pass all but the last argument to the preprocessor. */ + while (optind < ac - 1) { + if (i >= MAX_ARGS) + errx(EX_USAGE, "too many preprocessor options"); + args[i++] = av[optind++]; + } + } + av += optind; ac -= optind; if (ac != 1) diff --git a/sbin/ipfw/ipfw2.c b/sbin/ipfw/ipfw2.c index e9ea0e10c954..c038dd373afd 100644 --- a/sbin/ipfw/ipfw2.c +++ b/sbin/ipfw/ipfw2.c @@ -3429,28 +3429,8 @@ ipfw_readfile(int ac, char *av[]) pid_t preproc = 0; int c; - while ((c = getopt(ac, av, "D:U:p:q")) != -1) + while ((c = getopt(ac, av, "p:q")) != -1) { switch(c) { - case 'D': - if (!pflag) - errx(EX_USAGE, "-D requires -p"); - if (i > MAX_ARGS - 2) - errx(EX_USAGE, - "too many -D or -U options"); - args[i++] = "-D"; - args[i++] = optarg; - break; - - case 'U': - if (!pflag) - errx(EX_USAGE, "-U requires -p"); - if (i > MAX_ARGS - 2) - errx(EX_USAGE, - "too many -D or -U options"); - args[i++] = "-U"; - args[i++] = optarg; - break; - case 'p': pflag = 1; cmd = optarg; @@ -3467,6 +3447,19 @@ ipfw_readfile(int ac, char *av[]) " summary ``ipfw''"); } + if (pflag) + break; + } + + if (pflag) { + /* Pass all but the last argument to the preprocessor. */ + while (optind < ac - 1) { + if (i >= MAX_ARGS) + errx(EX_USAGE, "too many preprocessor options"); + args[i++] = av[optind++]; + } + } + av += optind; ac -= optind; if (ac != 1)