program cap(sin, sout, output); (* put capital letters inside quotes of a program thomas schneider copyright (c) 1989 module libraries required: delman, delmods *) label 1; (* the end of the program *) const (* begin module version *) version = 1.08; (* of cap.p 1989 July 8 *) (* end module version *) (* begin module describe.cap *) (* name cap: put capital letters inside quotes of a program synopsis cap(sin: in, sout: out,output: out) files sin: the source program or file sout: the source program with capital letters in all quote strings. output: messages to the user description A pascal program under Unix must be small characters, yet a database will often be in capital letters, so the program will not recognize the data. This program makes the sin program have capital letters only in the quote strings. author thomas d. schneider bugs none known *) (* end module describe.cap *) (* begin module cap.const *) single = ''''; (* a single quote mark *) double = '"'; (* a double quote mark *) var (* begin module cap.var *) sin, (* the source in file *) sout: (* the source out file *) text; (* end module cap.var *) (* begin module halt *) procedure halt; (* stop the program *) begin goto 1 end; (* begin module halt *) (* begin module cap.docomment *) procedure docomment(var sin,sout: text); (* do a comment: find the end of the comment and copy all of it from sin to sout *) var (* endcomment := false; the eoln wrecks the potential comment *) ch: char; (* a character from sin *) done: boolean; (* when we have found the end of the comment *) endcomment: boolean; (* if true, perhaps we are at the end *) begin endcomment := false; done := false; while (not eof(sin)) and (not done) do begin if eoln(sin) then begin readln(sin); writeln(sout); endcomment := false; end else begin read(sin,ch); write(sout,ch); if (ch = ')') and endcomment then done := true else endcomment := (ch = '*') end end end; (* end module cap.docomment *) (* begin module cap.doquote *) procedure doquote(var sin, sout: text; endquote: char; diff: integer); (* do a quote: copy from sin to sout until the endquote character is found in sin. all letters inside the quotes are made into upper case, by subtracting the value of diff. *) var ch: char; (* a character from sin *) begin ch := ' '; while (not eof(sin)) and (ch<>endquote) do begin if eoln(sin) then begin readln(sin); writeln(sout); end else begin read(sin,ch); if (ch in ['a'..'z']) then write(sout,chr(ord(ch)-diff)) else write(sout,ch) end end end; (* end module cap.doquote *) (* begin module cap.main *) procedure themain(var sin, sout: text); (* the main procedure of the program *) var ch: char; (* a character from sin *) diff: integer; (* the difference in ord between small and capital letters. the value of diff will change from one computer system to another, but the program will still work the same way. *) startcomment: boolean; (* true when a comment may have started *) begin writeln(output,' cap ',version:4:2); reset(sin); rewrite(sout); startcomment := false; diff := ord('a') - ord('A'); (* difference between small and caps *) while not eof(sin) do begin if eoln(sin) then begin readln(sin); writeln(sout); startcomment := false end else begin read(sin,ch); write(sout,ch); if (ch = '*') and startcomment then begin docomment(sin,sout); startcomment := false; end else begin if ch = '(' then startcomment := true else begin startcomment := false; if (ch = single) or (ch = double) then doquote(sin,sout,ch,diff) end end end end end; (* end module cap.main *) begin themain(sin,sout); 1: end.