summaryrefslogtreecommitdiff
path: root/app/conversion/1.0/src/ASKCNVRS.PAC
blob: 7d9dddd75895896d7c99667519e440623b6c6d90 (plain)
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
PACKET asksam conversion DEFINES append asksam field,
                                 append asksam record,
                                 convert to asksam :
LET card prefix = " +--",
    bo field    = "[ ",
    eo field    = " ]",
    eo line     = ""13""10"",
    eo record   = ""0"",
    eo doc      = ""0""0"",
    dummy fn    = "@";
LET max fields  = 50;
TEXT VAR in l, out l, appended l, asksam record, buffer;
INT VAR card no, in line no, out line no, last named field,
        start pos, end pos, card lines, first line;
FILE VAR f in, f out;
THESAURUS VAR field names;
ROW max fields BOOL VAR complex fields,
                        to be copied;
PROC convert to asksam (TEXT CONST input file) :
  IF NOT exists (input file) THEN errorstop ("") FI;
  TEXT CONST output file := dos file name (input file, "sam");
  forget (output file);
  f out := sequential file (output, output file);
  field names := empty thesaurus;
  IF input is eudas
     THEN convert eudas to asksam (input file)
  ELIF input is cardbox
     THEN convert cardbox to asksam
  ELSE stop process
  FI
.
input is eudas :
  type (old (input file)) = 3243
.
input is cardbox :
  IF type (old (input file)) = 1003
     THEN f in := sequential file (modify, input file);
          toline (f in, 1);
          down (f in, ""26""26"");
          pattern found
     ELSE FALSE
  FI
.
stop process :
  forget (output file, quiet);
  errorstop ("Konversion nur f"219"r EUDAS- und Cardbox-Dateien m"218"glich.")
END PROC convert to asksam;
PROC convert eudas to asksam (TEXT CONST file name) :
  oeffne (file name, FALSE);
  get field names;
  WHILE NOT dateiende REP
    transfer one record;
    weiter (1)
  PER;
  dateien loeschen (FALSE)
.
get field names :
  asksam record := "";
  last named field := anzahl felder;
  auf satz (1);
  FOR in line no FROM 1 UPTO last named field REP
    feld lesen (in line no, in l);
    IF in l <> ""
       THEN to be copied [in line no] := TRUE;
            complex fields [in line no] := is complex field;
            append field name (in l);
            feldnamen lesen (in line no, in l);
            append asksam field (in l)
       ELSE to be copied [in line no] := FALSE;
            append field name (dummy fn)
    FI
  PER;
  append asksam record;
  weiter (1)
.
is complex field :
  end pos := pos (in l, "{");
  IF end pos <> 0
     THEN end pos DECR 1;
          WHILE (in l SUB end pos) = " " REP
            end pos DECR 1
          PER;
          in l := subtext (in l, 1, end pos);
          TRUE
     ELSE FALSE
  FI
.
transfer one record :
  cout (satznummer);
  asksam record := "";
  out line no := 0;
  transfer fields;
  append asksam record
.
transfer fields :
  FOR in line no FROM 1 UPTO last named field REP
    IF to be copied [in line no] 
       THEN feld lesen (in line no, in l);
            IF in l <> ""
               THEN IF complex fields [in line no]
                       THEN transfer complex field (in l)
                       ELSE append asksam field (in l)
                    FI
            FI
    FI
  PER
END PROC convert eudas to asksam;
PROC transfer complex field (TEXT CONST l) :
  TEXT VAR transfer buffer;
  start pos := 1;
  REP
    start pos INCR 1;
    end pos := pos (l, "{", start pos + 1);
    IF end pos = 0
       THEN end pos := LENGTH l
       ELSE end pos DECR 1
    FI;
    WHILE (l SUB end pos) = " " REP
      end pos DECR 1
    PER;
    transfer buffer := subtext (l, start pos, end pos);
    change (transfer buffer, "}", "");
    append asksam field (transfer buffer);
    start pos := pos (l, "{", end pos)
  UNTIL start pos = 0 PER
END PROC transfer complex field;
PROC convert cardbox to asksam :
  BOOL VAR line end;
  ascertain number lines per card;
  convert file;
.
ascertain number lines per card :
  toline (f in, 1);
  col (f in, 1);
  downety (f in, card prefix);
  first line := line no (f in);
  down (f in, card prefix);
  card lines := line no (f in) - first line
.
convert file :
  line;
  input (f in);
  get field names;
  card no := 0;
  WHILE NOT eof (f in) REP
    transfer one card
  UNTIL asksam record = "" PER
.
get field names :
  last named field := 0;
  getline (f in, in l);
  get names from first lines;
  get names from bulk;
.
get names from first lines :
  FOR in line no FROM 1 UPTO card lines - 2 REP
    get cardbox line (in l);
    in l := compress (in l);
    IF in l > ""
       THEN append field name (in l);
            last named field := in line no
       ELSE append field name (dummy fn)
    FI
  PER;
.
get names from bulk :
  in line no := card lines - 2;
  get cardbox line (in l);
  end pos := 0;
  REP
    get card line (appended l, line end);
    IF line end
       THEN LEAVE get names from bulk
    ELIF appended l <> ""
       THEN in line no INCR 1;
            append field name (compress (appended l));
            last named field INCR 1
    FI;
  PER
END PROC convert cardbox to asksam;
PROC transfer one card :
  BOOL VAR line end;
  card no INCR 1;
  cout (card no);
  asksam record := "";
  transfer first lines;
  transfer bulk line;
  append asksam record
.
transfer first lines :
  getline (f in, in l);
  IF pos (in l, card prefix) <> 2
     THEN errorstop ("Programmfehler 1")
  ELIF pos (in l, "LAST CARD") <> 0
     THEN LEAVE transfer one card
  FI;
  out line no := 0;
  FOR in line no FROM 1 UPTO card lines - 2 REP
    get cardbox line (in l);
    IF pos (in l, ""25""25"") = 1
       THEN process hypertext
       ELSE append asksam field (in l)
    FI;
  PER
.
process hypertext :
  asksam record CAT ":"13""10""9"";
  end pos := pos (in l, ".card") - 1;
  appended l := subtext (in l, 55, end pos);
  asksam record CAT appended l;
  asksam record CAT ""255""13""10""13""10"";
  asksam record CAT "(Datei zum Thema `";
  asksam record CAT appended l;
  asksam record CAT "')"13""10"";
  out line no := 4
.
transfer bulk line :
  get cardbox line (in l);
  end pos := 0;
  first line := 0;
  in line no DECR 1;
  REP
    get card line (appended l, line end);
    IF line end
       THEN LEAVE transfer bulk line
    FI;
    in line no INCR 1;
    cout (in line no);
    append asksam field (appended l)
  PER
END PROC transfer one card;
PROC get cardbox line (TEXT VAR t) :
  getline (f in, t);
  start pos := pos (t, "|");
  IF start pos = 0
     THEN errorstop ("Programmfehler 2")
  FI;
  t := subtext (t, start pos + 1)
END PROC get cardbox line;
PROC get card line (TEXT VAR t, BOOL VAR end) :
  start pos := pos (in l, ""32"", ""255"", endpos + 1);
  IF start pos = 0
     THEN end := TRUE;
          LEAVE get card line
  FI;
  end pos := pos (in l, ""26"", start pos);
  IF end pos = 0     
     THEN end := TRUE;
          LEAVE get card line
  FI;
  end pos DECR 1;
  t := subtext (in l, start pos, end pos);
  end := FALSE
END PROC get card line;
PROC append asksam line (TEXT CONST t) :
  asksam record CAT t;
  out line no INCR 1;
  IF out line no MOD 20 = 0
     THEN asksam record CAT eo record
     ELSE asksam record CAT eo line
  FI
END PROC append asksam line;
PROC append asksam field (TEXT CONST t) :
  BOOL VAR named field;
  INT VAR s pos, e pos, length l;
  IF t > " " CAND in line no <= last named field
     THEN get field name (in line no, out l);
          IF out l <> dummy fn
             THEN out l CAT bo field;
                  named field := TRUE
             ELSE out l := "";
                  named field := FALSE
          FI
     ELSE out l := "";
          named field := FALSE
  FI;
  buffer := t;
  prepare line for asksam (buffer);
  out l CAT buffer;
  transfer line
.
transfer line :
  length l := LENGTH out l;
  e pos := -1;
  REP
    s pos := e pos + 2;
    IF (length l - s pos) > 79
       THEN determine e pos;
            transfer chunk
       ELSE transfer rest
    FI
  PER
.
determine e pos :
  e pos := s pos + 79;
  move before last blank
.
move before last blank :
  WHILE (out l SUB e pos) <> " " REP
    e pos DECR 1
  UNTIL e pos = s pos PER;
  IF e pos = s pos
     THEN e pos := s pos + 79
     ELSE e pos DECR 1
  FI
.
transfer chunk :
  append asksam line (subtext (out l, s pos, e pos));
.
transfer rest :
  buffer := subtext (out l, s pos);
  IF named field
     THEN buffer CAT eo field
  FI;
  append asksam line (buffer);
  LEAVE transfer line
END PROC append asksam field;
PROC append asksam record :
  IF was eo record
     THEN asksam record CAT eo record
     ELSE buffer := subtext (asksam record, 1, LENGTH asksam record - 2);
          buffer CAT eo doc;
          asksam record := buffer
  FI;
  putline (f out, asksam record)
.
was eo record :
  out line no MOD 20 = 0
END PROC append asksam record;
PROC prepare line for asksam (TEXT VAR t) :
  IF (t SUB LENGTH t) = " "
     THEN t := subtext (t, 1, LENGTH t - 1)
  FI;
  replace eumel special characters (t);
  change all (t, "[", ""174"");
  change all (t, "]", ""175"");
  change all (t, "#on(""i"")#", "<I>");
  change all (t, "#off(""i"")#", "<i>")
END PROC prepare line for asksam;
PROC append field name (TEXT CONST fn) :
  INT VAR index;
  buffer := fn;
  prepare line for asksam (buffer);
  insert (field names, buffer, index)
END PROC append field name;
PROC get field name (INT CONST index, TEXT VAR fn) :
  fn := name (field names, index)
END PROC get field name;
END PACKET asksam conversion;