home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / c / 11478 < prev    next >
Encoding:
Internet Message Format  |  1992-07-22  |  2.7 KB

  1. Path: sparky!uunet!mcsun!fuug!demos!kiae!glas!demos!druid.uucp!darcy
  2. From: darcy@druid.uucp
  3. Newsgroups: comp.lang.c
  4. Date: 18 Jul 92 03:26 MDT
  5. Subject: Simple preprocessor
  6. Sender: Notesfile to Usenet Gateway <notes@glas.apc.org>
  7. Message-ID: <1992Jul17.232621.20226@druid.uuc>
  8. Nf-ID: #N:1992Jul17.232621.20226@druid.uuc:-1295377463:001:2384
  9. Nf-From: druid.uucp!darcy    Jul 18 03:26:00 1992
  10. Lines: 63
  11.  
  12.  
  13. scs@adam.mit.edu (Steve Summit) writes:
  14. >Once of these days, someone should write a good, simple
  15. >preprocessor, perhaps simply a stripped-down cpp, that handled
  16. >#include, #ifdef, and simple #define (and *maybe* macros with
  17. >arguments), which *would* be appropriate for general-purpose,
  18. >non-C preprocessing tasks such as Makefiles, calendar files,
  19. >crontab files, etc.  (Hmm; gotta write myself another note.)
  20.  
  21. TA DA!!!
  22.  
  23. Introducing mkfiles(3) (Actually that's too much like a BSD utility I
  24. believe but that's the name I started with.  I'll probably change it.)
  25.  
  26. It's not quite ready for distribution yet but here is a glimpse.
  27.  
  28. First of all the '#' is a comment character like just about every
  29. Unix utility except cc.  Blank lines are ignored.  There are hooks
  30. if you need '#'  or blank lines in the output.
  31.  
  32. Preprocessor directives start with '@'.  These include;
  33.  
  34.   @DEFINE          Define a macro
  35.   @DEFAULT         Like @DEFINE but only if not already defined
  36.   @UNDEFINE        Undef same
  37.   @INCLUDE         Include a file
  38.   @PACKAGE         Include a file from a predefined directory
  39.   @FILE            Redirect output to a new file
  40.   @PRINT           Print to standard output regardless of current output
  41.   @SHOW            Show defined macros (for debugging)
  42.   @CLEAR           Clear all macros to a specific point
  43.   @IFDEF           Conditional
  44.   @IFNDEF               "
  45.   @ELIFDEF             "
  46.   @ELIFNDEF            "
  47.   @ELSE                "
  48.   @ENDIF           End conditional
  49.   @QUOTE           Quote all lines (a specialty thing I needed)
  50.   @FOR             For loop construct
  51.   @END             End for loop
  52.   @ERROR           Print message and exit
  53.  
  54. Macros can take arguments and defaults can be specified for the arguments.
  55. Here is a sample macro:
  56.     @DEFINE foo bar $(1:zap)
  57. And it's expansion:
  58.     $(foo:goo)    ==>     bar goo
  59.     $(foo)        ==>     bar zap
  60.  
  61. The sample script creates a skeleton SVR4 device driver including the
  62. system files, Makefile, Bare C file, etc.
  63.  
  64. The distribution includes my getarg(3) and getline(3), valuable utilities
  65. in their own right if I say so myself.
  66.  
  67. I have a little more testing to do on it and then I will probably post it.
  68.  
  69. -- 
  70. D'Arcy J.M. Cain (darcy@druid)     |
  71. D'Arcy Cain Consulting             |   There's no government
  72. Toronto, Ontario, Canada           |   like no government!
  73. +1 416 424 2871          DoD#0082  |
  74.  
  75.