Subject: Simple config(8) patch: "package" keyword
To: None <tech-userlevel@netbsd.org>
From: Jason R Thorpe <thorpej@wasabisystems.com>
List: tech-userlevel
Date: 11/17/2002 15:34:49
--/9DWx/yDrRhgMJTb
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Folks..
I've just checked in this very simple patch that makes it somewhat easier
to add 3rd-party software packages to the kernel. Before a sequence like
this would be used:
prefix "../path/to/some/directory"
include "files.package"
prefix
This patch allows you to simply say:
package "../path/to/some/directory/files.package"
and it performs exactly the same steps as above.
--
-- Jason R. Thorpe <thorpej@wasabisystems.com>
--/9DWx/yDrRhgMJTb
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=config-patch
Index: defs.h
===================================================================
RCS file: /cvsroot/syssrc/usr.sbin/config/defs.h,v
retrieving revision 1.8
diff -c -r1.8 defs.h
*** defs.h 2002/10/09 20:17:00 1.8
--- defs.h 2002/11/17 23:33:10
***************
*** 476,481 ****
--- 476,482 ----
/* scan.l */
int currentline(void);
int firstfile(const char *);
+ void package(const char *);
int include(const char *, int, int, int);
/* sem.c, other than for yacc actions */
Index: gram.y
===================================================================
RCS file: /cvsroot/syssrc/usr.sbin/config/gram.y,v
retrieving revision 1.38
diff -c -r1.38 gram.y
*** gram.y 2002/10/11 01:48:25 1.38
--- gram.y 2002/11/17 23:33:10
***************
*** 104,111 ****
%token AND AT ATTACH BUILD CINCLUDE COMPILE_WITH CONFIG DEFFS DEFINE DEFOPT
%token DEFPARAM DEFFLAG DEFPSEUDO DEVICE DEVCLASS DUMPS ENDFILE XFILE XOBJECT
%token FILE_SYSTEM FLAGS IDENT INCLUDE XMACHINE MAJOR MAKEOPTIONS
! %token MAXUSERS MAXPARTITIONS MINOR ON OPTIONS PREFIX PSEUDO_DEVICE ROOT
! %token SOURCE TYPE WITH NEEDS_COUNT NEEDS_FLAG NO BLOCK CHAR DEVICE_MAJOR
%token <val> NUMBER
%token <str> PATHNAME QSTRING WORD EMPTY
%token ENDDEFS
--- 104,111 ----
%token AND AT ATTACH BUILD CINCLUDE COMPILE_WITH CONFIG DEFFS DEFINE DEFOPT
%token DEFPARAM DEFFLAG DEFPSEUDO DEVICE DEVCLASS DUMPS ENDFILE XFILE XOBJECT
%token FILE_SYSTEM FLAGS IDENT INCLUDE XMACHINE MAJOR MAKEOPTIONS
! %token MAXUSERS MAXPARTITIONS MINOR ON OPTIONS PACKAGE PREFIX PSEUDO_DEVICE
! %token ROOT SOURCE TYPE WITH NEEDS_COUNT NEEDS_FLAG NO BLOCK CHAR DEVICE_MAJOR
%token <val> NUMBER
%token <str> PATHNAME QSTRING WORD EMPTY
%token ENDDEFS
***************
*** 245,250 ****
--- 245,253 ----
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(); };
***************
*** 267,272 ****
--- 270,276 ----
object |
device_major { do_devsw = 1; } |
include |
+ package |
prefix |
DEVCLASS WORD { (void)defattr($2, NULL, NULL, 1); } |
DEFFS fsoptfile_opt deffses { deffilesystem($2, $3); } |
Index: scan.l
===================================================================
RCS file: /cvsroot/syssrc/usr.sbin/config/scan.l,v
retrieving revision 1.35
diff -c -r1.35 scan.l
*** scan.l 2002/11/07 21:06:04 1.35
--- scan.l 2002/11/17 23:33:10
***************
*** 47,52 ****
--- 47,53 ----
#include <sys/param.h>
#include <errno.h>
+ #include <libgen.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
***************
*** 119,124 ****
--- 120,126 ----
object return XOBJECT;
on return ON;
options return OPTIONS;
+ package return PACKAGE;
prefix return PREFIX;
pseudo-device return PSEUDO_DEVICE;
root return ROOT;
***************
*** 207,212 ****
--- 209,243 ----
yyfile = conffile = fname;
yyline = 1;
return (0);
+ }
+
+ /*
+ * Add a "package" to the configuration. This is essentially
+ * syntactic sugar around the sequence:
+ *
+ * prefix ../some/directory
+ * include "files.package"
+ * prefix
+ */
+ void
+ package(const char *fname)
+ {
+ char *fname1 = estrdup(fname);
+ char *fname2 = estrdup(fname);
+ char *dir = dirname(fname1);
+ char *file = basename(fname2);
+
+ /*
+ * Push the prefix on to the prefix stack and process the include
+ * file. When we reach the end of the include file, inserting
+ * the PREFIX token into the input stream will pop the prefix off
+ * of the prefix stack.
+ */
+ prefix_push(dir);
+ (void) include(file, PREFIX, 0, 1);
+
+ free(fname1);
+ free(fname2);
}
/*
--/9DWx/yDrRhgMJTb--