%%s 3/3/354 %%d D 1.5 15-Jun-83 12:36:12 sventek 5 4 %%c Removed trailing periods from quoted strings, as they are no longer needed. %%s 45/1/312 %%d D 1.4 14-Dec-82 16:44:21 sventek 4 3 %%c Added documentation on the ratfor-specific nature of the selection %%c of candidate words for replacement, as well as on the keyword %%c highlighting possible with ~bin/fmtpf. Added fmtpf to the archive %%c as well. %%s 5/5/308 %%d D 1.3 01-Nov-82 19:10:32 sventek 3 2 %%c Made appropriate modifications to convert all occurrences of the string %%c ''' to the string '@''. The previous form is now a syntax error, due to %%c the extension to ratfor to permit "'" to be used as a quoted string %%c delimiter %%s 37/9/276 %%d D 1.2 10-Jun-82 14:19:29 j 2 1 %%c Modified txtrpl.w`txtrpl.r`gtnwrd to understand RATFOR quoted strings, %%c character constants and comments. The text replacements will NOT %%c occur for tokens found inside of these constructs %%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 %%D 2 #-h- txtrpl.r 2482 asc 25-mar-82 09:01:16 v1.1 (sw-tools v1.1) %%E 2 %%I 2 %%D 3 #-h- txtrpl.r 2941 asc 26-may-82 14:26:17 j (sventek j) %%E 3 %%E 2 %%I 3 %%D 5 #-h- txtrpl.r 2953 asc 01-nov-82 18:20:08 sventek (joseph sventek) %%E 5 %%E 3 %%I 5 #-h- txtrpl.r 2956 asc 15-jun-83 12:35:49 sventek (joseph sventek) %%E 5 #-h- main 268 asc 25-mar-82 09:00:59 v1.1 (sw-tools v1.1) DRIVER(txtrpl) character buf(MAXLINE) ext_func integer gtnwrd ext_subr query, inipat, replac call query("usage: txtrpl patfile ...") call inipat(buf) # initialize patterns while (gtnwrd(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 %%D 2 #-h- gtnwrd 472 asc 25-mar-82 09:01:00 v1.1 (sw-tools v1.1) %%E 2 %%I 2 %%D 3 #-h- gtnwrd 938 asc 26-may-82 14:23:57 j (sventek j) %%E 3 %%E 2 %%I 3 #-h- gtnwrd 939 asc 01-nov-82 18:19:55 sventek (joseph sventek) %%E 3 integer function gtnwrd(buf, int) %%D 2 character buf(MAXLINE), c %%E 2 %%I 2 character buf(MAXLINE), c, trmchr %%E 2 filedes int integer i, t ext_subr ungtch ext_func character gtch ext_func integer type, length c = gtch(buf(1), int) %%I 2 buf(2) = EOS %%E 2 if (c == EOF) return(EOF) %%D 2 if (type(c) != LETTER) buf(2) = EOS else %%E 2 %%I 2 i = 2 if (type(c) == LETTER) %%E 2 { %%D 2 for (i=2; gtch(c, int) != EOF; i=i+1) %%E 2 %%I 2 while (gtch(c, int) != EOF) %%E 2 { t = type(c) if (t != LETTER & t != DIGIT & t != '_') break else %%D 2 buf(i) = c %%E 2 %%I 2 call chcopy(c, buf, i) %%E 2 } call ungtch(c, int) %%D 2 buf(i) = EOS %%E 2 } %%I 2 else if (c == '"') { trmchr = c while (gtch(c, int) != EOF) { call chcopy(c, buf, i) if (c == trmchr & buf(i-2) != '@@') break } } %%D 3 else if (c == ''') %%E 3 %%I 3 else if (c == '@'') %%E 3 { c = gtch(c, int) call chcopy(c, buf, i) if (c == '@@') { c = gtch(c, int) call chcopy(c, buf, i) } c = gtch(c, int) call chcopy(c, buf, i) } else if (c == '#') while (gtch(c, int) != EOF) { call chcopy(c, buf, i) if (c == '@n') break } %%E 2 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 %%D 5 #-h- ungtch 188 asc 25-mar-82 09:01:01 v1.1 (sw-tools v1.1) %%E 5 %%I 5 #-h- ungtch 187 asc 15-jun-83 12:35:30 sventek (joseph sventek) %%E 5 subroutine ungtch(c, int) character c filedes int include cunget ext_subr error if (pbchar != EOS) %%D 5 call error("Attempt to push back more than one character.") %%E 5 %%I 5 call error("Attempt to push back more than one character") %%E 5 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 %%D 3 #-h- pf 1051 asc 25-mar-82 09:01:19 v1.1 (sw-tools v1.1) %%E 3 %%I 3 #-h- pf 1052 asc 01-nov-82 18:20:10 sventek (joseph sventek) %%E 3 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 '/' %%D 3 SQUOTE ''' %%E 3 %%I 3 SQUOTE '@'' %%E 3 STAR '*' TILDE '~' UNDERLINE '_' %%D 4 #-h- txtrpl.fmt 1348 asc 25-mar-82 09:01:20 v1.1 (sw-tools v1.1) %%E 4 %%I 4 #-h- txtrpl.fmt 1821 asc 14-dec-82 16:43:05 sventek (joseph sventek) %%E 4 .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. %%I 4 `txtrpl's selection of candidate words for replacement is dependent upon ratfor program syntax, in that words inside of comments, quoted strings and character constants are not eligible for replacement. This fact can be exploited to generate source listings of ratfor code with boldfaced keywords by executing the following commands: .sp alist file | txtrpl ~bin/fmtpf .sp The resulting output file can be piped into `os' or `lpr' for final disposition to a print device. %%E 4 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 %%I 4 #-h- fmtpf 1252 asc 14-dec-82 16:43:07 sventek (joseph sventek) DRETURN DDDRRREEETTTUUURRRNNN DRIVER DDDRRRIIIVVVEEERRR DS_DECL DDDSSS___DDDEEECCCLLL PB_DECL PPPBBB___DDDEEECCCLLL break bbbrrreeeaaakkk case cccaaassseee character ccchhhaaarrraaacccttteeerrr default dddeeefffaaauuulllttt define dddeeefffiiinnneee do dddooo else eeelllssseee elsedef eeelllssseeedddeeefff ext_func eeexxxttt___fffuuunnnccc ext_subr eeexxxttt___sssuuubbbrrr filedes fffiiillleeedddeeesss for fffooorrr if iiifff ifdef iiifffdddeeefff ifnotdef iiifffnnnoootttdddeeefff include iiinnncccllluuudddeee integer iiinnnttteeegggeeerrr linepointer llliiinnneeepppoooiiinnnttteeerrr next nnneeexxxttt pointer pppoooiiinnnttteeerrr repeat rrreeepppeeeaaattt return rrreeetttuuurrrnnn select ssseeellleeecccttt string ssstttrrriiinnnggg subroutine sssuuubbbrrrooouuutttiiinnneee switch ssswwwiiitttccchhh until uuunnntttiiilll while wwwhhhiiillleee %%E 4 %%E 1