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 / ipl / progs / cstrings.icn < prev    next >
Text File  |  2000-07-29  |  2KB  |  94 lines

  1. ############################################################################
  2. #
  3. #    File:     cstrings.icn
  4. #
  5. #    Subject:  Program to print strings in C files
  6. #
  7. #    Author:   Robert J. Alexander
  8. #
  9. #    Date:     September 17, 1990
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #  Program to print all strings (enclosed in double quotes) in C source
  18. #  files.
  19. #
  20.  
  21. procedure main(arg)
  22.    local c,f,fn,line,lineNbr,s
  23.    if *arg = 0 then stop("Usage: cstrings file...")
  24.    every fn := !arg do {
  25.       f := open(fn) | stop("Can't open \"",fn,"\"")
  26.       lineNbr := 0
  27.       while line := read(f) do line ? {
  28.      lineNbr +:= 1
  29.      while tab(upto('/"\'')) do {
  30.         case move(1) of {
  31.            #
  32.            #  Comment -- handled because it could contain something that
  33.            #  looks like a string.
  34.            #
  35.            "/": {
  36.           if ="*" then {
  37.              while not tab(find("*/") + 2) do {
  38.             &subject := read(f) | stop("Unexpected EOF in comment")
  39.             lineNbr +:= 1
  40.             }
  41.              }
  42.           }
  43.            #
  44.            #  String
  45.            #
  46.            "\"": {
  47.           s := "\""
  48.           while s ||:= tab(upto('"\\')) do {
  49.              s ||:= c := move(1)
  50.              case c of {
  51.             "\\": {
  52.                if not (s ||:= move(1)) then {
  53.                   s[-1] := ""
  54.                   &subject := read(f) |
  55.                     stop("Unexpected EOF in string")
  56.                   lineNbr +:= 1
  57.                   }
  58.                }
  59.             "\"": {
  60.                break
  61.                }
  62.             }
  63.              }
  64.           write("+",lineNbr," ",fn," ",s)
  65.           }
  66.            #
  67.            #  Character constant -- handled because it might contain
  68.            #  a double quote, which could be mistaken for the start
  69.            #  of a string.
  70.            #
  71.            "'": {
  72.           while tab(upto('\'\\')) do {
  73.              c := move(1)
  74.              case c of {
  75.             "\\": {
  76.                if not move(1) then {
  77.                   &subject := read(f) |
  78.                     stop("Unexpected EOF in character constant")
  79.                   lineNbr +:= 1
  80.                   }
  81.                }
  82.             "'": {
  83.                break
  84.                }
  85.             }
  86.              }
  87.           }
  88.            }
  89.         }
  90.      }
  91.       close(f)
  92.       }
  93. end
  94.