Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/config Move package/cinclude/include handling from t...



details:   https://anonhg.NetBSD.org/src/rev/aa15ad2eddf0
branches:  trunk
changeset: 584162:aa15ad2eddf0
user:      martin <martin%NetBSD.org@localhost>
date:      Sat Sep 10 15:38:46 2005 +0000

description:
Move package/cinclude/include handling from the parser to the scanner,
where it belongs. This has the side effect of fixing PR toolchain/30903.

diffstat:

 usr.bin/config/defs.h |   3 +-
 usr.bin/config/gram.y |  18 +++---------
 usr.bin/config/scan.l |  72 +++++++++++++++++++++++++++++++++++++++++++++++---
 3 files changed, 74 insertions(+), 19 deletions(-)

diffs (231 lines):

diff -r 6acb59cd0e2c -r aa15ad2eddf0 usr.bin/config/defs.h
--- a/usr.bin/config/defs.h     Sat Sep 10 14:53:34 2005 +0000
+++ b/usr.bin/config/defs.h     Sat Sep 10 15:38:46 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: defs.h,v 1.1 2005/06/05 18:19:53 thorpej Exp $ */
+/*     $NetBSD: defs.h,v 1.2 2005/09/10 15:38:46 martin Exp $  */
 
 /*
  * Copyright (c) 1992, 1993
@@ -389,6 +389,7 @@
 int    maxbdevm;                       /* max number of block major */
 int    maxcdevm;                       /* max number of character major */
 int    do_devsw;                       /* 0 if pre-devsw config */
+int    oktopackage;                    /* 0 before setmachine() */
 
 TAILQ_HEAD(, files)    allfiles;       /* list of all kernel source files */
 TAILQ_HEAD(, objects)  allobjects;     /* list of all kernel object and
diff -r 6acb59cd0e2c -r aa15ad2eddf0 usr.bin/config/gram.y
--- a/usr.bin/config/gram.y     Sat Sep 10 14:53:34 2005 +0000
+++ b/usr.bin/config/gram.y     Sat Sep 10 15:38:46 2005 +0000
@@ -1,5 +1,5 @@
 %{
-/*     $NetBSD: gram.y,v 1.1 2005/06/05 18:19:53 thorpej Exp $ */
+/*     $NetBSD: gram.y,v 1.2 2005/09/10 15:38:46 martin Exp $  */
 
 /*
  * Copyright (c) 1992, 1993
@@ -101,12 +101,12 @@
 
 %token AND AT ATTACH
 %token BLOCK BUILD
-%token CHAR CINCLUDE COMPILE_WITH CONFIG
+%token CHAR COMPILE_WITH CONFIG
 %token DEFFS DEFINE DEFOPT DEFPARAM DEFFLAG DEFPSEUDO DEVICE DEVCLASS DUMPS
 %token DEVICE_MAJOR
 %token ENDFILE
 %token XFILE FILE_SYSTEM FLAGS
-%token IDENT INCLUDE
+%token IDENT
 %token XMACHINE MAJOR MAKEOPTIONS MAXUSERS MAXPARTITIONS MINOR
 %token NEEDS_COUNT NEEDS_FLAG NO
 %token XOBJECT ON OPTIONS
@@ -181,7 +181,6 @@
 topthing:
        SOURCE filename '\n'            { if (!srcdir) srcdir = $2; } |
        BUILD  filename '\n'            { if (!builddir) builddir = $2; } |
-       include '\n' |
        '\n';
 
 machine_spec:
@@ -252,13 +251,6 @@
        COMPILE_WITH stringvalue        { $$ = $2; } |
        /* empty */                     { $$ = NULL; };
 
-include:
-       INCLUDE filename                { (void) include($2, 0, 0, 1); } |
-       CINCLUDE filename               { (void) include($2, 0, 1, 1); };
-
-package:
-       PACKAGE filename                { package($2); };
-
 prefix:
        PREFIX filename                 { prefix_push($2); } |
        PREFIX                          { prefix_pop(); };
@@ -280,8 +272,6 @@
        file |
        object |
        device_major                    { do_devsw = 1; } |
-       include |
-       package |
        prefix |
        DEVCLASS WORD                   { (void)defattr($2, NULL, NULL, 1); } |
        DEFFS fsoptfile_opt deffses     { deffilesystem($2, $3); } |
@@ -649,6 +639,8 @@
         */
        if (include("conf/files", ENDFILE, 0, 0) != 0)
                exit(1);
+
+       oktopackage = 1;
 }
 
 static void
diff -r 6acb59cd0e2c -r aa15ad2eddf0 usr.bin/config/scan.l
--- a/usr.bin/config/scan.l     Sat Sep 10 14:53:34 2005 +0000
+++ b/usr.bin/config/scan.l     Sat Sep 10 15:38:46 2005 +0000
@@ -1,5 +1,5 @@
 %{
-/*     $NetBSD: scan.l,v 1.1 2005/06/05 18:19:53 thorpej Exp $ */
+/*     $NetBSD: scan.l,v 1.2 2005/09/10 15:38:46 martin Exp $  */
 
 /*
  * Copyright (c) 1992, 1993
@@ -48,12 +48,15 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <stddef.h>
+#include <ctype.h>
 #include "defs.h"
 #include "gram.h"
 
 int    yyline;
 const char *yyfile;
 const char *lastfile;
+char curinclpath[PATH_MAX];
 
 /*
  * Data for returning to previous files from include files.
@@ -68,13 +71,16 @@
 };
 static struct incl *incl;
 static int endinclude(void);
+static int getincludepath(void);
 
 #define        yywrap() 1
 
 %}
 
 PATH   [A-Za-z_0-9]*[./][-A-Za-z_0-9./]*
+QCHARS ([^"\n]|\\\")+
 WORD   [A-Za-z_][-A-Za-z_0-9]*
+FILENAME       ({PATH}|\"{QCHARS}\")
 
 %%
                /* Local variables for yylex() */
@@ -86,7 +92,6 @@
 block          return BLOCK;
 build          return BUILD;
 char           return CHAR;
-cinclude       return CINCLUDE;
 compile-with   return COMPILE_WITH;
 config         return CONFIG;
 deffs          return DEFFS;
@@ -103,7 +108,6 @@
 file-system    return FILE_SYSTEM;
 flags          return FLAGS;
 ident          return IDENT;
-include                return INCLUDE;
 machine                return XMACHINE;
 major          return MAJOR;
 makeoptions    return MAKEOPTIONS;
@@ -116,7 +120,6 @@
 object         return XOBJECT;
 on             return ON;
 options                return OPTIONS;
-package                return PACKAGE;
 prefix         return PREFIX;
 pseudo-device  return PSEUDO_DEVICE;
 root           return ROOT;
@@ -126,6 +129,32 @@
 
 \+=            return PLUSEQ;
 
+include[ \t]+{FILENAME}        {
+               if (getincludepath()) {
+                       include(curinclpath, 0, 0, 1);
+               } else {
+                       yyerror("bad include path-name");
+               }
+       }
+
+cinclude[ \t]+{FILENAME}       {
+               if (getincludepath()) {
+                       include(curinclpath, 0, 1, 1);
+               } else {
+                       yyerror("bad cinclude path-name");
+               }
+       }
+
+package[ \t]+{FILENAME}        {
+               if (!oktopackage) {
+                       yyerror("package not allowed here");
+               } else if (getincludepath()) {
+                       package(curinclpath);
+               } else {
+                       yyerror("bad package path-name");
+               }
+       }
+
 {PATH} {
                yylval.str = intern(yytext);
                return PATHNAME;
@@ -140,7 +169,8 @@
                yylval.str = intern("");
                return EMPTY;
        }
-\"([^"\n]|\\\")+ {
+
+\"{QCHARS}     {
                tok = input();  /* eat closing quote */
                if (tok != '"') {
                        error("closing quote missing\n");
@@ -353,6 +383,38 @@
 }
 
 /*
+ * Extract the pathname from a include/cinclude/package into curinclpath
+ */
+static int
+getincludepath()
+{
+       const char *p = yytext;
+
+       while (*p && isascii((signed char)*p) && !isspace((signed char)*p))
+               p++;
+       while (*p && isascii((signed char)*p) && isspace((signed char)*p))
+               p++;
+       if (!*p)
+               return 0;
+       if (*p == '"') {
+               ptrdiff_t len;
+               const char *e = strchr(p+1, '"');
+
+               if (!e) return 0;
+               len = e-p-1;
+               if (len > sizeof(curinclpath)-1)
+                       len = sizeof(curinclpath)-1;
+               strncpy(curinclpath, p+1, sizeof(curinclpath));
+               curinclpath[len] = '\0';
+       } else {
+               strncpy(curinclpath, p, sizeof(curinclpath));
+               curinclpath[sizeof(curinclpath)-1] = '\0';
+       }
+
+       return 1;
+}
+
+/*
  * Terminate the most recent inclusion.
  */
 static int



Home | Main Index | Thread Index | Old Index