home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / src / common / fixgram.icn < prev    next >
Text File  |  2000-07-29  |  1KB  |  49 lines

  1. # fix grammar after it has been put through the C preprosesor
  2. #
  3. #    allow at most 3 blank lines in a row
  4. #    change /*#...*/ to #...
  5. #    remove lines begining with #
  6. #    remove some of the extra tabs introduced by macro definitions and insert
  7. #    some newlines
  8.  
  9. procedure main()
  10.     local s,n
  11.  
  12.     write("/*")
  13.     write(" * W A R N I N G:")
  14.     write(" *")
  15.     write(" *    this file has been preprocessed")
  16.     write(" *    any changes must be made to the original file")
  17.     write(" */")
  18.     write()
  19.  
  20.     n := 0
  21.     while s := read() do {
  22.     while s == "" do {
  23.         if (n +:= 1) <= 3 then write()
  24.         s := read() | break
  25.         }
  26.     s ? (="/*#" & write("#",tab(find("*/"))) & (n := 0)) |
  27.         ="#" |
  28.         (fix_tabs() & (n := 0))
  29.     }
  30. end
  31.  
  32. procedure fix_tabs()
  33.     if ="\t\t\t" then {
  34.         tab(many('\t'))
  35.     writes("\t\t")
  36.     }
  37.     while writes(tab(upto('{\t'))) do
  38.     if writes(="{") then
  39.         tab(many(' \t'))
  40.     else if ="\t\t\t" then {
  41.         writes("\n\t\t")
  42.         tab(many('\t'))
  43.         }
  44.     else
  45.         writes(tab(many('\t')))
  46.     write(tab(0))
  47.     return
  48. end
  49.