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 / icvt.icn < prev    next >
Text File  |  2001-05-02  |  2KB  |  98 lines

  1. ############################################################################
  2. #
  3. #    File:     icvt.icn
  4. #
  5. #    Subject:  Program for ASCII/EBCDIC program conversion
  6. #
  7. #    Author:   Cheyenne Wills, modified by Ralph E. Griswold
  8. #
  9. #    Date:     May 2, 2001
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #  This program converts Icon programs from ASCII syntax to EBCDIC syntax
  18. #  or vice versa. The option -a converts to ASCII, while the option
  19. #  -e converts to EBCDIC. The program given in standard input is written
  20. #  in converted form to standard output.
  21. #
  22. ############################################################################
  23.  
  24. global outf,process,bb,quotechar
  25. global nrbrack,nlbrack,nrbrace,nlbrace,rbrack,lbrack,rbrace,lbrace
  26.  
  27. procedure main(args)
  28.    local line
  29.  
  30.    case map(args[1]) | stop("Usage: icvt -a | -e") of {
  31.        "-a" : {
  32.        lbrace := "$("; nlbrace := "{"
  33.        rbrace := "$)"; nrbrace := "}"
  34.        lbrack := "$<"; nlbrack := "["
  35.        rbrack := "$>"; nrbrack := "]"
  36.        bb := '$'
  37.        }
  38.        "-e" : {
  39.        lbrace := "{"; nlbrace := "$(";
  40.        rbrace := "}"; nrbrace := "$)";
  41.        lbrack := "["; nlbrack := "$<";
  42.        rbrack := "]"; nrbrack := "$>";
  43.        bb := '[]{}'
  44.        }
  45.        default :
  46.        stop("Usage: icvt -a | -e")
  47.        }
  48.  
  49.    process := standard
  50.  
  51.    while line := read() do {
  52.        line ||:= "\n"
  53.        line ? while not pos(0) do
  54.        process()
  55.        }
  56.  
  57. end
  58.  
  59. procedure standard()
  60.    writes(tab(upto( '"\'#' ++ bb))) | (writes(tab(0)) & return)
  61.  
  62.    if match("#") then {
  63.        writes(tab(0))
  64.        }
  65.    else if any('\'"') then {
  66.        process := inquote
  67.        quotechar := move(1)
  68.        writes(quotechar)
  69.        }
  70.    else if match(lbrack) then {
  71.        move(*lbrack)
  72.        writes(nlbrack)
  73.        }
  74.    else if match(rbrack) then {
  75.        move(*rbrack)
  76.        writes(nrbrack)
  77.        }
  78.    else if match(lbrace) then {
  79.        move(*lbrace)
  80.        writes(nlbrace)
  81.        }
  82.    else if match(rbrace) then {
  83.        move(*rbrace)
  84.        writes(nrbrace)
  85.        }
  86.    else writes(move(1))
  87.    return
  88. end
  89.  
  90. procedure inquote()
  91.    writes( tab(upto( quotechar ++ '\\')) ) |
  92.        (writes(tab(0)) & return)
  93.    writes(="\\") & writes(move(1)) & return
  94.    writes( =quotechar )
  95.    process := standard
  96.    return
  97. end
  98.