[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/yahrzeit/bin/ -> fmt (source)

   1  #!/usr/local/bin/perl
   2  'di';
   3  'ig00';
   4  #
   5  #  fmt - flexible macro translator
   6  #   %W%
   7  #
   8  #   Copyright (c) 1990 Emax Computer Systems Inc.  Ottawa, Ontario
   9  #   
  10  #   Author:  Barry Friedman  friedman%chekov@uunet.uu.net
  11  #                            (...!uunet!chekov!friedman)
  12  #
  13  #   Usage:  UNLIMITED, providing this copyright notice is retained
  14  #
  15  #   THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  16  #   IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  17  #   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  18  
  19  #  Constants
  20  
  21  $USAGE="usage: fmt -p [-o outfl ] [-t templ] [-d lpdest] [-f fmtr ] file\n";
  22  
  23  $TEMPLATE='template';
  24  $DEF_FMTR="/utils/bin/tbl -D | /utils/bin/eroff -mm -c1";
  25  $PV_FMTR="tbl | nroff -mm |col|pg";
  26  
  27  push(@INC, "/utils/lib/perl");
  28  
  29  do 'getopts.pl';
  30  
  31  
  32  do Getopts('t:o:d:f:p') || die("$USAGE\n");
  33  
  34  $look_keywd=1;
  35  $n_key=0;
  36  while (<>) 
  37  {
  38      #
  39      #  look for lines of the form  :key:
  40      #
  41      if ($look_keywd)
  42      { if(/:(\w+):/)
  43        {    $keywd=$1;
  44              $look_keywd=0;
  45              s/:\w+://;
  46              s/^[ \t]*//;
  47              s/[ \t]*$//;
  48              s/^\n$//;
  49              $line=$_;
  50              next;
  51          }
  52      }
  53      else
  54      { if(/:(\w+):/)
  55          {    $look_keywd=1;
  56              chop($line);
  57              $key{$keywd} = $line;
  58              redo;
  59          }
  60          $line=$line . $_;
  61      }
  62  }
  63  # last keyword
  64  chop($line);
  65  $key{$keywd} = $line;
  66  
  67  
  68  if (defined $opt_t) { $template=$opt_t; }
  69  else { $template=$TEMPLATE;} ;
  70  $ENV{"LPDEST"}= $opt_d if (defined $opt_d);
  71  
  72  open (infile, "$template") || die("can't open template") ;
  73  $fmtcmd= (defined $opt_p) ? "| $PV_FMTR" :
  74      (defined $opt_o && defined $opt_f) ? "| $opt_f".">$opt_o" :
  75      (defined $opt_o) ? ">$opt_o" : 
  76      (defined $opt_f) ? "| $opt_f" : 
  77      "| $DEF_FMTR";
  78  open (outfile, $fmtcmd) || die("can't open >tmpinv") ;
  79  
  80  while (<infile>) 
  81  {
  82      if (/#/) {
  83          while(1)
  84          {
  85              last if(! /#([^#]+)#/);
  86              if (defined ($value=$key{$1})) {
  87                  s/#$1#/$value/e;
  88                  next;
  89              } elsif ( s/^([^#]*)#\w+#/\1/ ) { 
  90                  next;
  91              } else {
  92                  last if (! /(.*#.*)(#.*#.*)/);
  93                  print outfile $1;
  94                  $_ =$2 . "\n";
  95              }
  96          }
  97      }
  98      print outfile;
  99  }
 100  close infile;
 101  close outfile;
 102  exit(0);
 103  
 104  .00;            # finish .ig
 105   
 106  'di            \" finish diversion--previous line must be blank
 107  .nr nl 0-1        \" fake up transition to first page again
 108  .nr % 0            \" start at page 1
 109  ';__END__ ############# From here on it's a standard manual page ############
 110  .TH FMT 1 "December 5, 1990"
 111  .AT 3
 112  .SH NAME
 113  fmt \- flexible macro formatter
 114  .SH SYNOPSIS
 115  .B fmt 
 116  [
 117  .B -o 
 118  .I out 
 119  ] [
 120  .B -t 
 121  .I templ
 122  ] [
 123  .B -d 
 124  .I lpdest 
 125  ] [
 126  .B -p 
 127  .B -f 
 128  .I fmtr ] 
 129  .I file
 130  .SH DESCRIPTION
 131  .I Fmt
 132  provides a simple way to do simple macro replacement on template files.
 133  The default template file `template' may contain any text.  
 134  Patterns in the template of the form #tag# (/#\\w+#) are
 135  replaced with corresponding replacement text as described below.
 136  The replacement text is taken from
 137  .I file
 138  or standard input which
 139  consists of one or more replacement lines
 140  of the form:
 141  .P
 142  :tag: replacement text
 143  .br
 144  replacement line
 145  .br
 146  replacement line
 147  .br
 148  .P
 149  Each occurence of #tag# in the template is replaced with the
 150  corresponding :tag: replacement text which runs from the end
 151  of the final `:', skipping any leading and trailing white space,
 152  until the next :tag: or eof.
 153  If a tag is not present in the input file it is replaced
 154  by a null string.
 155  The output is written to a default formatter pipe defined in the
 156  program as $DEF_FMTR.
 157  .P
 158  The following options to \fIfmt\fR are available:
 159  .TP \w'-mxxxx'u
 160  \fB-o\fIout\fP
 161  Write the output to file \fIout\fP.
 162  .TP
 163  \fB-t\fItempl\fR
 164  Use file name 
 165  .I templ
 166  instead of `template'.
 167  .TP
 168  \fB-p
 169  Write the output to a default previewer pipe defined in the program
 170  as $PV_FMTR.
 171  .TP
 172  \fB-f\fIfmtr\fR
 173  Use the argument as a pipe to which to send the output.
 174  .TP
 175  \fB-d\fIlpdest\fR
 176  Set the environment variable LPDEST to 
 177  .I lpdest .
 178  .SH ENVIRONMENT
 179  No environment variables are used.
 180  .SH FILES
 181  None
 182  .SH AUTHOR
 183  Barry Friedman
 184  .SH "SEE ALSO"
 185  .SH DIAGNOSTICS
 186  .SH BUGS
 187  .ex


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7