home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / unix / misc / 4086 < prev    next >
Encoding:
Text File  |  1992-11-10  |  6.0 KB  |  168 lines

  1. Newsgroups: comp.unix.misc
  2. Path: sparky!uunet!convex!convex!tchrist
  3. From: Tom Christiansen <tchrist@convex.COM>
  4. Subject: Re: Is anyone using m4?
  5. Originator: tchrist@pixel.convex.com
  6. Sender: usenet@news.eng.convex.com (news access account)
  7. Message-ID: <1992Nov10.164718.19827@news.eng.convex.com>
  8. Date: Tue, 10 Nov 1992 16:47:18 GMT
  9. Distribution: comp.*.unix
  10. Reply-To: tchrist@convex.COM (Tom Christiansen)
  11. References: <crigler.720808909@eola.cs.ucf.edu> <1992Nov7.005445.12288@prl.dec.com>
  12. Nntp-Posting-Host: pixel.convex.com
  13. Organization: Convex Computer Corporation, Colorado Springs, CO
  14. Keywords: m4,macro,preprocessor
  15. X-Disclaimer: This message was written by a user at CONVEX Computer
  16.               Corp. The opinions expressed are those of the user and
  17.               not necessarily those of CONVEX.
  18. Lines: 148
  19.  
  20. From the keyboard of boyd@prl.dec.com (Boyd Roberts):
  21. :Yeah, we use it to generate N window manager rc's from a set
  22. :of standard configs that all of them include.  m4 is cool.
  23.  
  24. m4 is so amazingly cool that before perl, it used to be my
  25. favorite unix tool. :-)
  26.  
  27. consider the following m4 program, which generates a syslog.conf
  28. file with all kinds of conditionals, like 4.2 vs 4.3, strange
  29. LOG_ entries derived from #include files, expanding the operations alias
  30. for biffing, and knowing what machines belong to what admin domain
  31. it's in so we know about sending to the right loghost.  First, 
  32. the thing that makes the machine definitions:
  33.  
  34.     define(`TMP',maketemp(/tmp/syslog.XXXXX))dnl
  35.     changequote([,])dnl
  36.     syscmd([hostname | sed 's/.*/define(`'"HOST'"',`'"&'"')dnl/'] > TMP)dnl
  37.     changequote(`,')dnl
  38.     include(TMP)dnl
  39.     changequote(^A,^B)dnl
  40.     syscmd(^A(echo 'r /usr/adm/MACHINES';
  41.           echo '%s/[    ][a-zA-Z0-9_]*\>/\U&/g';
  42.           echo '%p';
  43.           echo 'q!') | ex - - | tr -d '\015' | awk '$1 == "^BHOST^A" { 
  44.         for (i=2;i<NF;i++) 
  45.             if ($i && $i != ".") {
  46.             pos = index($i,"=");
  47.             if (pos) { 
  48.                 printf "define(%c%s%c,%c%s%c)dnl\n", \
  49.                 96, substr($i,1,pos-1), 39,\
  50.                 96, substr($i,pos+1,length($i)-pos), 39; 
  51.             } else {
  52.                 printf "define(%c%s%c)dnl\n", 96, $i, 39;
  53.             }
  54.             }}'^B > TMP)dnl
  55.     changequote(`,')dnl
  56.     include(TMP)dnl
  57.     syscmd(rm TMP)dnl
  58.     ifdef(`MIS',    `define(`ADMIN',`mis')define(`LOGHOST',`convex')')dnl
  59.     ifdef(`MKTG',   `define(`ADMIN',`mktg')define(`LOGHOST',`convex1')')dnl
  60.     ifdef(`TAC',    `define(`ADMIN',`tac')define(`LOGHOST',`sushi')')dnl
  61.     ifdef(`C1',`define(CONVEX)')dnl
  62.     ifdef(`C2',`define(CONVEX)')dnl
  63.     ifdef(`C3',`define(CONVEX)')dnl
  64.     ifdef(`LOGHOST',,`ifdef(`DOALLPASSWD',`define(`ADMIN',`engr')define(`LOGHOST',`c
  65.     oncave')')')dnl
  66.     ifelse(LOGHOST,HOST,`undefine(`LOGHOST')')dnl
  67.  
  68. now the syslog.conf.global file itself, which uses the preceding one:
  69.  
  70.     #
  71.     changequote({,})dnl
  72.     ifdef(impossible_thing,{#
  73.     # global syslog configuration file.
  74.     #
  75.     # This file is processed by m4 so be careful to quote (`') names
  76.     # that match m4 reserved words.  Also, within ifdef's, arguments
  77.     # containing commas must be quoted.  This hackery crafted by
  78.     # tchrist.
  79.     #
  80.     # Note: The interpretation given within to `LOGHOST' is opposite
  81.     # what sun does.  That is, if it is defined, it is the name of the 
  82.     # host who collects syslog information for this administrative domain.
  83.     # We still log locally as well in case of network snafus.
  84.     },{dnl
  85.     # This is the local syslog.conf file; it has been generated 
  86.     # automatically using "m4 < syslog.conf.global > syslog.conf",
  87.     # and therefore should never be edited by hand.  It has included
  88.     # syslog.conf.local if this file existed.
  89.     #
  90.     # Note: Have to exclude user from most lines so that user.alert
  91.     #    and user.emerg are not included, because old sendmails
  92.     #    will generate them for debugging information.  If you
  93.     #    have no 4.2BSD based systems doing network logging, you
  94.     #    can remove all the special cases for "user" logging.
  95.     #
  96.     })dnl
  97.     changequote(`,')dnl
  98.     include(`/usr/adm/etc/stddefs.m4')dnl
  99.     changequote({,})dnl
  100.     syscmd({sed -n -e 's/^[     ]*#define[     ][     ]*\(LOG_[A-Z0-9]*\)[     ].*/define(`\1'"')dnl/p" < /usr/include/syslog.h} > TMP)dnl
  101.     changequote(`,')dnl
  102.     include(TMP)dnl
  103.     ifdef(`LOG_DAEMON',
  104.     `
  105.     # critical and authorization stuff gets wide notice
  106.     #
  107.     *.warn;user,kern.none            /usr/adm/log/critical
  108.     *.warn;kern,user.none;auth.info        /dev/console'
  109.     ifdef(`LOGHOST',`
  110.     `
  111.     # forward noteworthy stuff to 'LOGHOST`, our administrative domain master
  112.     #'
  113.     *.warn;kern`,'auth.info;local7.none    @LOGHOST
  114.     ')dnl
  115.     `
  116.     *.warn;user,kern.none    kuryla,root
  117.  
  118.     kern.debug                /usr/adm/log/kernlog
  119.     auth.debug                /usr/adm/log/authlog
  120.     daemon.debug                /usr/adm/log/daemonlog
  121.     lpr.debug                /usr/adm/log/lpd-errs
  122.     mail.debug                /usr/spool/mqueue/syslog
  123.     syslog.debug                /usr/adm/log/syslog
  124.     user.debug                /usr/adm/log/messages'
  125.  
  126.     `# next entries do not always exist on all old-style systems
  127.     #'
  128.     ifdef(`LOG_BATCH',`batch.info                /usr/adm/log/batchlog
  129.     ')dnl
  130.     ifdef(`LOG_CRON',`cron.info                /usr/adm/log/cronlog
  131.     ')dnl
  132.     ifdef(`LOG_NEWS',`news.info                /usr/adm/log/newslog
  133.     #ifelse(`concave',HOST,,``#' to track new notes locking for tchrist
  134.     #news.debug                @concave')
  135.     #')dnl
  136.     ifdef(`LOG_TAPE',`tape.debug                /usr/adm/log/tapelog
  137.     ')dnl
  138.     `# local0 is errlogd, local7 come from the cisco routers
  139.     #
  140.     local0.debug                /usr/adm/log/errlog
  141.     local1.debug                            /usr/adm/log/monitorlog
  142.     local3.debug                @mikey
  143.     local7.debug                /usr/adm/log/ciscolog
  144.     #
  145.     # END OF /etc/syslog.conf.global
  146.     # local stuff follows and comes from syslog.conf.local'
  147.     sinclude(`/etc/syslog.conf.local')dnl
  148.     ,# old style syslog
  149.     9/usr/spool/mqueue/syslog
  150.     7/usr/adm/log/critical
  151.     5/dev/console
  152.  
  153.     changequote({,})dnl
  154.     syscmd({/usr/lib/sendmail -bv operations | sed -e 's/.*!//' -e 's/\..*//'} > TMP)dnl
  155.     include(TMP)root
  156.     )dnl
  157.     syscmd(rm TMP)dnl
  158.  
  159.  
  160. aren't you glad i use perl now? :-)
  161.  
  162. --tom
  163. -- 
  164.     Tom Christiansen      tchrist@convex.com      convex!tchrist
  165.  
  166. Time flies like an arrow
  167. Fruit flies like a banana
  168.