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
|
############################################################################
#
# File: cstrings.icn
#
# Subject: Program to print strings in C files
#
# Author: Robert J. Alexander
#
# Date: September 17, 1990
#
############################################################################
#
# This file is in the public domain.
#
############################################################################
#
# Program to print all strings (enclosed in double quotes) in C source
# files.
#
procedure main(arg)
local c,f,fn,line,lineNbr,s
if *arg = 0 then stop("Usage: cstrings file...")
every fn := !arg do {
f := open(fn) | stop("Can't open \"",fn,"\"")
lineNbr := 0
while line := read(f) do line ? {
lineNbr +:= 1
while tab(upto('/"\'')) do {
case move(1) of {
#
# Comment -- handled because it could contain something that
# looks like a string.
#
"/": {
if ="*" then {
while not tab(find("*/") + 2) do {
&subject := read(f) | stop("Unexpected EOF in comment")
lineNbr +:= 1
}
}
}
#
# String
#
"\"": {
s := "\""
while s ||:= tab(upto('"\\')) do {
s ||:= c := move(1)
case c of {
"\\": {
if not (s ||:= move(1)) then {
s[-1] := ""
&subject := read(f) |
stop("Unexpected EOF in string")
lineNbr +:= 1
}
}
"\"": {
break
}
}
}
write("+",lineNbr," ",fn," ",s)
}
#
# Character constant -- handled because it might contain
# a double quote, which could be mistaken for the start
# of a string.
#
"'": {
while tab(upto('\'\\')) do {
c := move(1)
case c of {
"\\": {
if not move(1) then {
&subject := read(f) |
stop("Unexpected EOF in character constant")
lineNbr +:= 1
}
}
"'": {
break
}
}
}
}
}
}
}
close(f)
}
end
|