#!/usr/local/bin/perl 'di'; 'ig00'; # # fmt - flexible macro translator # %W% # # Copyright (c) 1990 Emax Computer Systems Inc. Ottawa, Ontario # # Author: Barry Friedman friedman%chekov@uunet.uu.net # (...!uunet!chekov!friedman) # # Usage: UNLIMITED, providing this copyright notice is retained # # THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. # Constants $USAGE="usage: fmt -p [-o outfl ] [-t templ] [-d lpdest] [-f fmtr ] file\n"; $TEMPLATE='template'; $DEF_FMTR="/utils/bin/tbl -D | /utils/bin/eroff -mm -c1"; $PV_FMTR="tbl | nroff -mm |col|pg"; push(@INC, "/utils/lib/perl"); do 'getopts.pl'; do Getopts('t:o:d:f:p') || die("$USAGE\n"); $look_keywd=1; $n_key=0; while (<>) { # # look for lines of the form :key: # if ($look_keywd) { if(/:(\w+):/) { $keywd=$1; $look_keywd=0; s/:\w+://; s/^[ \t]*//; s/[ \t]*$//; s/^\n$//; $line=$_; next; } } else { if(/:(\w+):/) { $look_keywd=1; chop($line); $key{$keywd} = $line; redo; } $line=$line . $_; } } # last keyword chop($line); $key{$keywd} = $line; if (defined $opt_t) { $template=$opt_t; } else { $template=$TEMPLATE;} ; $ENV{"LPDEST"}= $opt_d if (defined $opt_d); open (infile, "$template") || die("can't open template") ; $fmtcmd= (defined $opt_p) ? "| $PV_FMTR" : (defined $opt_o && defined $opt_f) ? "| $opt_f".">$opt_o" : (defined $opt_o) ? ">$opt_o" : (defined $opt_f) ? "| $opt_f" : "| $DEF_FMTR"; open (outfile, $fmtcmd) || die("can't open >tmpinv") ; while () { if (/#/) { while(1) { last if(! /#([^#]+)#/); if (defined ($value=$key{$1})) { s/#$1#/$value/e; next; } elsif ( s/^([^#]*)#\w+#/\1/ ) { next; } else { last if (! /(.*#.*)(#.*#.*)/); print outfile $1; $_ =$2 . "\n"; } } } print outfile; } close infile; close outfile; exit(0); .00; # finish .ig 'di \" finish diversion--previous line must be blank .nr nl 0-1 \" fake up transition to first page again .nr % 0 \" start at page 1 ';__END__ ############# From here on it's a standard manual page ############ .TH FMT 1 "December 5, 1990" .AT 3 .SH NAME fmt \- flexible macro formatter .SH SYNOPSIS .B fmt [ .B -o .I out ] [ .B -t .I templ ] [ .B -d .I lpdest ] [ .B -p .B -f .I fmtr ] .I file .SH DESCRIPTION .I Fmt provides a simple way to do simple macro replacement on template files. The default template file `template' may contain any text. Patterns in the template of the form #tag# (/#\\w+#) are replaced with corresponding replacement text as described below. The replacement text is taken from .I file or standard input which consists of one or more replacement lines of the form: .P :tag: replacement text .br replacement line .br replacement line .br .P Each occurence of #tag# in the template is replaced with the corresponding :tag: replacement text which runs from the end of the final `:', skipping any leading and trailing white space, until the next :tag: or eof. If a tag is not present in the input file it is replaced by a null string. The output is written to a default formatter pipe defined in the program as $DEF_FMTR. .P The following options to \fIfmt\fR are available: .TP \w'-mxxxx'u \fB-o\fIout\fP Write the output to file \fIout\fP. .TP \fB-t\fItempl\fR Use file name .I templ instead of `template'. .TP \fB-p Write the output to a default previewer pipe defined in the program as $PV_FMTR. .TP \fB-f\fIfmtr\fR Use the argument as a pipe to which to send the output. .TP \fB-d\fIlpdest\fR Set the environment variable LPDEST to .I lpdest . .SH ENVIRONMENT No environment variables are used. .SH FILES None .SH AUTHOR Barry Friedman .SH "SEE ALSO" .SH DIAGNOSTICS .SH BUGS .ex