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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
PACKET eumel file utilities
DEFINES sort,
in denoter,
even number of command delimiters,
extract command,
next text command pos,
word wrap,
enumerator,
enumeration offset :
PROC sort (THESAURUS VAR th) :
disable stop;
FILE VAR d := sequential file (output, "dummy");
d FILLBY th;
sort ("dummy");
th := empty thesaurus;
input (d);
th FILLBY d;
forget ("dummy", quiet);
enable stop
END PROC sort;
BOOL PROC in denoter (TEXT CONST l, INT CONST p) :
INT VAR number of quotes := 0,
last quote pos,
quote pos := 0;
quote count loop;
number of quotes MOD 2 = 1
.
quote count loop :
REP
last quote pos := quote pos;
quote pos := pos (l, """", last quote pos + 1, p - 1);
IF quote pos <> 0
THEN number of quotes INCR 1
ELSE LEAVE quote count loop
FI
PER
END PROC in denoter;
BOOL PROC even number of command delimiters (TEXT CONST l, INT CONST end pos) :
INT VAR number := 0, current pos := 1, cross pos;
counting loop;
number MOD 2 = 0
.
counting loop :
REP
cross pos := pos (l, "#", current pos, end pos);
IF cross pos <> 0
THEN number INCR 1;
current pos := cross pos + 1
FI
UNTIL cross pos = 0 PER
END PROC even number of command delimiters;
BOOL PROC even number of command delimiters (TEXT CONST l) :
even number of command delimiters (l, LENGTH l)
END PROC even number of command delimiters;
PROC extract command (TEXT CONST l, INT CONST start pos, INT VAR next pos,
TEXT VAR cmd) :
next pos := pos (l, "#", start pos + 1);
IF next pos = 0
THEN errorstop ("unkorrekte Textanweisung")
FI;
cmd := subtext (l, start pos + 1, next pos - 1);
next pos INCR 1
END PROC extract command;
PROC next text command pos (TEXT CONST t, INT CONST start pos,
INT VAR start cross pos, end cross pos) :
start cross pos := pos (t, "#", start pos);
IF start cross pos <> 0
THEN end cross pos := pos (t, "#", start cross pos + 1)
FI
END PROC next text command pos;
BOOL PROC word wrap (TEXT CONST file name) :
FILE VAR f := sequential file (input, file name);
word wrap (f)
END PROC word wrap;
BOOL PROC word wrap (FILE VAR f) :
TEXT VAR l;
modify (f);
toline (f, lines (f));
WHILE line no (f) > 1 REP
read record (f, l);
IF l <> ""
THEN LEAVE word wrap WITH (l SUB LENGTH l) = " "
ELSE up (f, 1)
FI
PER;
FALSE
END PROC word wrap;
INT PROC enumeration offset (TEXT CONST this line, next line,
BOOL CONST in enumeration, INT CONST start pos) :
TEXT VAR initial chunk, next line initial chunk;
INT VAR blank pos, next line blank pos,
text start pos := 0, next line text start pos;
IF NOT only command line (this line)
THEN ascertain text start pos
FI;
text start pos
.
ascertain text start pos :
blank pos := pos (this line, " ", start pos);
IF blank pos > 1 CAND blank pos < LENGTH this line
THEN text start pos := pos (this line, ""33"", ""255"", blank pos);
IF is enumeration
THEN text start pos DECR 1
ELSE text start pos := 0
FI
FI
.
is enumeration :
neighboring lines correspond CAND this line is enumerated
.
neighboring lines correspond :
in enumeration COR next line corresponds
.
next line corresponds :
next line blank pos := pos (next line, " ", start pos);
next line text start pos :=
pos (next line, ""33"", ""255"", next line blank pos);
text start pos = next line text start pos CAND
(next line indented COR also enumerated)
.
next line indented :
pos (next line, ""33"", ""255"", 1) = next line text start pos
.
also enumerated :
next line initial chunk
:= subtext (next line, start pos, next line blank pos - 1);
enumerator (next line initial chunk)
.
this line is enumerated :
initial chunk := subtext (this line, start pos, blank pos - 1);
enumerator (initial chunk)
END PROC enumeration offset;
BOOL PROC enumerator (TEXT CONST t) :
t = "-" COR substantial enumerator
.
substantial enumerator :
INT CONST l := LENGTH t;
TEXT CONST last char := t SUB l;
l < 20 CAND last char = ":" COR
l < 7 CAND pos (".)", last char) <> 0
END PROC enumerator;
END PACKET eumel file utilities;
|