%%s 0/0/0 %%d D 1.1 25-Mar-82 12:16:01 v1.1 1 0 %%c Version 1.1 is the Spring 1982 Distribution of the LBL/Hughes release %%c of the Software Tools Virtual Operating System software and documentation. %%T %%I 1 #-h- txtrpl.r 2482 asc 25-mar-82 09:01:16 v1.1 (sw-tools v1.1) #-h- main 268 asc 25-mar-82 09:00:59 v1.1 (sw-tools v1.1) DRIVER(txtrpl) character buf(MAXLINE) ext_func integer gtword ext_subr query, inipat, replac call query("usage: txtrpl patfile ...") call inipat(buf) # initialize patterns while (gtword(buf, STDIN) != EOF) # get next word call replac(buf, STDOUT) DRETURN end #-h- gtch 195 asc 25-mar-82 09:00:59 v1.1 (sw-tools v1.1) character function gtch(c, int) character c filedes int ext_func character getch include cunget if (pbchar != EOS) { c = pbchar pbchar = EOS } else c = getch(c, int) return(c) end #-h- gtword 472 asc 25-mar-82 09:01:00 v1.1 (sw-tools v1.1) integer function gtword(buf, int) character buf(MAXLINE), c filedes int integer i, t ext_subr ungtch ext_func character gtch ext_func integer type, length c = gtch(buf(1), int) if (c == EOF) return(EOF) if (type(c) != LETTER) buf(2) = EOS else { for (i=2; gtch(c, int) != EOF; i=i+1) { t = type(c) if (t != LETTER & t != DIGIT & t != '_') break else buf(i) = c } call ungtch(c, int) buf(i) = EOS } return(length(buf)) end #-h- inipat 704 asc 25-mar-82 09:01:01 v1.1 (sw-tools v1.1) define(Memory_size,5000) subroutine inipat(buf) character buf(MAXLINE), pat(MAXLINE), file(FILENAMESIZE) integer i, j, junk filedes int ext_func integer getarg, getlin, getwrd, length ext_func filedes open ext_subr tbinit, cant, skipbl, scopy, tbinst, close DS_DECL(Mem, Memory_size) include cunget pbchar = EOS call tbinit(Memory_size) for (i=1; getarg(i, file, FILENAMESIZE) != EOF; i=i+1) { int = open(file, READ) if (int == ERR) call cant(file) while (getlin(buf, int) != EOF) { j = 1 junk = getwrd(buf, j, pat) call skipbl(buf, j) call scopy(buf, j, buf, 1) j = length(buf) buf(j) = EOS call tbinst(pat, buf) } call close(int) } return end #-h- ungtch 188 asc 25-mar-82 09:01:01 v1.1 (sw-tools v1.1) subroutine ungtch(c, int) character c filedes int include cunget ext_subr error if (pbchar != EOS) call error("Attempt to push back more than one character.") pbchar = c return end #-h- replac 217 asc 25-mar-82 09:01:02 v1.1 (sw-tools v1.1) subroutine replac(buf, out) character buf(MAXLINE), defn(MAXLINE) filedes out ext_func integer tblook ext_subr putlin if (tblook(buf, defn) == YES) call putlin(defn, out) else call putlin(buf, out) return end #-h- cunget 81 asc 25-mar-82 09:01:18 v1.1 (sw-tools v1.1) common / cunget / pbchar character pbchar # pushed back character - init = EOS #-h- pf 1051 asc 25-mar-82 09:01:19 v1.1 (sw-tools v1.1) NEWLINE '@n' TAB '@t' ACCENT '`' AMPER '&' AMPERSAND '&' ATSIGN '@@' BACKSLASH '\' BANG '!' BAR '|' BIGA 'A' BIGB 'B' BIGC 'C' BIGD 'D' BIGE 'E' BIGF 'F' BIGG 'G' BIGH 'H' BIGI 'I' BIGJ 'J' BIGK 'K' BIGL 'L' BIGM 'M' BIGN 'N' BIGO 'O' BIGP 'P' BIGQ 'Q' BIGR 'R' BIGS 'S' BIGT 'T' BIGU 'U' BIGV 'V' BIGW 'W' BIGX 'X' BIGY 'Y' BIGZ 'Z' BLANK ' ' CARET '^' COLON ':' COMMA ',' DASH '-' DIG0 '0' DIG1 '1' DIG2 '2' DIG3 '3' DIG4 '4' DIG5 '5' DIG6 '6' DIG7 '7' DIG8 '8' DIG9 '9' DOLLAR '$' DQUOTE '"' EQUALS '=' GREATER '>' LBRACE '{' LBRACK '[' LESS '<' LETA 'a' LETB 'b' LETC 'c' LETD 'd' LETE 'e' LETF 'f' LETG 'g' LETH 'h' LETI 'i' LETJ 'j' LETK 'k' LETL 'l' LETM 'm' LETN 'n' LETO 'o' LETP 'p' LETQ 'q' LETR 'r' LETS 's' LETT 't' LETU 'u' LETV 'v' LETW 'w' LETX 'x' LETY 'y' LETZ 'z' LPAREN '(' MINUS '-' PERCENT '%' PERIOD '.' PLUS '+' QMARK '?' RBRACE '}' RBRACK ']' RPAREN ')' SEMICOL ';' SHARP '#' SLASH '/' SQUOTE ''' STAR '*' TILDE '~' UNDERLINE '_' #-h- txtrpl.fmt 1348 asc 25-mar-82 09:01:20 v1.1 (sw-tools v1.1) .so ~bin/manhdr .hd Txtrpl (1) 11-Mar-82 perform generalized text replacement .sy txtrpl patfile ... .ds `txtrpl' provides a general way to perform text replacement (NOT regular expressions) without embedding the (text,replacement text) pairs in the source file. After loading the (text,replacement text) pairs from the named pattern files in the command line, `txtrpl' reads words from standard input, looks each word up in a lookup table, and either writes out the replacement text on standard output or the word, depending upon whether it was found in the table or not. Only a single lookup is done. Words consist of letters, digits and underline ('_') characters, starting with a letter. The form of the pattern files is quite simple; each (text,replacement text) pair occupies a line. Leading blanks on the line are ignored, the token to be scanned for is the first word found, any intevening blanks are ignored, and the replacement text is everything else up to the end of line. In the regular language expression of the tools, each line is of the form .ce %*[A-Za-z][A-Za-z0-9_]**??*$ where represents a blank character. Case is important in the comparisons. .fl .sa macro - macro processor .br ed - text editor for description of regular expressions .br xch - extended change utility .di .au Joe Sventek .bu %%E 1