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 / c2icn.icn < prev    next >
Text File  |  2000-07-29  |  2KB  |  88 lines

  1. ############################################################################
  2. #
  3. #    File:     c2icn.icn
  4. #
  5. #    Subject:  Program to assist C-to-Icon porting
  6. #
  7. #    Author:   Robert J. Alexander
  8. #
  9. #    Date:     March 11, 1993
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #  Filter to do some of the mundane work involved in porting a C
  18. #  program to Icon.
  19. #
  20. #  - Reformats comments, moving embedded comments to end of line
  21. #  - Removes the ";" from ends of lines
  22. #  - Reformats line-continued strings
  23. #  - Changes = to :=
  24. #  - Changes -> to .
  25. #
  26. ############################################################################
  27.  
  28. procedure main(arg)
  29.    local c, comment, line, tline
  30.  
  31.    while line := trim(read(),' \t') do line ? {
  32.       line := comment := ""
  33.       while line ||:= tab(upto('\'"/=-')) do {
  34.      case c := move(1) of {
  35.         "\"" | "'": {
  36.            line ||:= c
  37.            repeat {
  38.           until line ||:= tab(find(c) + 1) do {
  39.              line ||:= tab(0)
  40.              if line[-1] == "\\" then line[-1] := "_"
  41.              else stop("unbalanced quotes")
  42.              Out(line)
  43.              line := ""
  44.              &subject := read()
  45.              }
  46.           if not (line[-2] == "\\" & not (line[-3] == "\\")) then break
  47.           }
  48.            }
  49.         "/": {
  50.            if ="*" then {
  51.           until comment ||:= trim(tab(find("*/")),' \t') do {
  52.              comment ||:= trim(tab(0),' \t')
  53.              Out(line,comment)
  54.              line := comment := ""
  55.              &subject := trim(read(),' \t')
  56.              }
  57.           move(2)
  58.           }
  59.            }
  60.         "=": {
  61.            if ="=" then line ||:= "=="
  62.            else if any('<>!',line[-1]) then line ||:= c
  63.            else line ||:= ":="
  64.            }
  65.         "-": {
  66.            if =">" then line ||:= "."
  67.            else line ||:= c
  68.            }
  69.         default: line ||:= c
  70.         }
  71.      }
  72.       line ||:= tab(0)
  73.       tline := trim(line)
  74.       if tline[-1] == ";" then {
  75.      line := tline[1:-1] || line[*tline + 1:0]
  76.      }
  77.       Out(line,comment)
  78.       }
  79. end
  80.  
  81.  
  82. procedure Out(line,comment)
  83.    line ||:= "#" || ("" ~== \comment)
  84.    line := trim(line,' \t')
  85.    write(line)
  86.    return
  87. end
  88.