home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1996 May / PCOnline_05_1996.bin / linux / source / contrib / smail / smail-3.1 / smail-3 / smail-3.1.28 / util / mkuuwho.awk < prev    next >
Text File  |  1992-07-11  |  4KB  |  192 lines

  1. # @(#)util/mkuuwho.awk    1.3 7/11/92 11:40:20
  2. #
  3. # mkpath.awk perform awk pre-processing of an input file
  4. #
  5. #    Copyright (C) 1988 Ronald S. Karr and Landon Curt Noll
  6. #    Copyright (C) 1992 Ronald S. Karr
  7. #
  8. # See the file COPYING, distributed with smail, for restriction
  9. # and warranty information.
  10. #
  11. # Some awk's don't process paragraphs in the order that they
  12. # appear in the file, so we are forced to make this program
  13. # non-deterministic.
  14.  
  15. ### initial setup
  16. #
  17. BEGIN {
  18.  
  19. #   clear line counts
  20.     lineno = 0;
  21. #   not in a block initially
  22.     inblock = 0;
  23. #   no errors so far
  24.     errno = 0;
  25. #   line modes
  26.     mode_file = 1;
  27.     mode_cmd = 2;
  28.     mode_lit = 3;
  29.     mode = 0;
  30.  
  31. #   preset shell commands
  32.     gleem = "$GLEEM";
  33. }
  34.  
  35. ### per line debug and processing
  36. #
  37. {
  38.  
  39. #   note another line, echo it if -v
  40.     ++lineno;
  41.     if ( VERBOSE > 0 && NF > 0 ) {
  42.     print PROG": line", lineno":", $0 | "cat 1>&2";
  43.     }
  44. }
  45.  
  46. ### ignore blank lines
  47. #
  48. NF < 1 {
  49.     next;
  50. }
  51.  
  52. ### pre-processing of lines with args
  53. #
  54. NF > 1 {
  55.  
  56. #   find string beyond the first field
  57.     args = substr($0, index($0,$1)+length($1));    # remove field 1
  58.     if ( $2 ~ /^`/ && $NF ~ /`$/ ) {
  59.     mode = mode_cmd;                # cmd output
  60.     # remove backquotes
  61.     args = substr(args, index(args,$2)+1, length(args)-index(args,$2)-1);
  62.     } else {
  63.     if ( $2 ~ /^\'/ && $NF ~ /\'$/ ) {
  64.         mode = mode_lit;                # text literal
  65.     } else {
  66.         mode = mode_file;                # data file
  67.     }
  68.         args = substr(args, index(args,$2));
  69.     }
  70. }
  71.  
  72. ### map - store map commands into WORK
  73. #
  74. $1 == "map" {
  75.  
  76.     if ( NF <= 1 ) {
  77.     print "echo", PROG, ": line", lineno":", $1, "no args 1>&2";
  78.     errno = 1;
  79.     if (ERR > 0) {
  80.         exit;        # END will be processed
  81.     }
  82.     } else {
  83.     if ( inblock == 0 ) {
  84.         print "(";
  85.         inblock = 1;
  86.     }
  87.     if (mode == mode_cmd) {
  88.         print args, "|", gleem, "-f -";
  89.     }
  90.     if (mode == mode_lit) {
  91.         print "echo", args, "|", gleem, "-f -";
  92.     }
  93.     if (mode == mode_file) {
  94.         print gleem, "-d $CWD -f /dev/null", args;
  95.     }
  96.     }
  97.     next;
  98. }
  99.  
  100. ### safemap - store map commands into WORK
  101. #
  102. $1 == "safemap" {
  103.  
  104.     if ( NF <= 1 ) {
  105.     print "echo", PROG, ": line", lineno":", $1, "no args 1>&2";
  106.     errno = 2;
  107.     if (ERR > 0) {
  108.         exit;        # END will be processed
  109.     }
  110.     } else {
  111.     if ( inblock == 0 ) {
  112.         print "(";
  113.         inblock = 1;
  114.     }
  115.     if (mode == mode_cmd) {
  116.         print args, "|", gleem, "-F -f -";
  117.     }
  118.     if (mode == mode_lit) {
  119.         print "echo", args, "|", gleem, "-F -f -";
  120.     }
  121.     if (mode == mode_file) {
  122.         print gleem, "-F -d $CWD -f /dev/null", args;
  123.     }
  124.     }
  125.     next;
  126. }
  127.  
  128. ### cd - store cd directory changing commands into WORK
  129. #
  130. $1 == "cd" {
  131.  
  132.     if ( NF > 2 ) {
  133.     print "echo", PROG, ": line", lineno":", $0, "too many args 1>&2";
  134.     errno = 3;
  135.     if (ERR > 0) {
  136.         exit;        # END will be processed
  137.     }
  138.     }
  139. #   cd by itself refers to the dir from where mkpath was started
  140.     if ( NF == 1 ) {
  141.     print "cd $PWD";
  142.     print "CWD=$PWD";
  143.     }
  144.     if ( NF == 2 ) {
  145. #    cd with a '-' refers to the dir that the input file is in
  146.     if ( $2 == "-" ) {
  147.         print "cd $CD";
  148.         print "CWD=$PWD";
  149. #    otherwise cd to the arg
  150.     } else {
  151.         print "cd", $2;
  152.         print "CWD="$2;
  153.     }
  154.     }
  155.     next;
  156. }
  157.  
  158. ### sh - store a SHELL command into a file
  159. #
  160. $1 == "sh" {
  161.  
  162.     if ( NF <= 1 ) {
  163.     print "echo", PROG, ": line", lineno":", $1, "no args 1>&2";
  164.     errno = 4;
  165.     if (ERR > 0) {
  166.         exit;        # END will be processed
  167.     }
  168.     } else {
  169.     print args;
  170.     }
  171.     next;
  172. }
  173.  
  174. ### pathalias, pathsort - end a block with pathalias(8) plus optional args
  175. #
  176. $1 == "pathalias" || $1 == "pathsort" {
  177.     if ( inblock > 0 ) {
  178.     print ")";
  179.     }
  180.     inblock = 0;
  181.     next;
  182. }
  183.  
  184. ### END - the end of a config file has an implied pathsort if it needs one
  185. #
  186. END {
  187.  
  188.     if ( inblock > 0 ) {
  189.     print ")";
  190.     }
  191. }
  192.