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