[go: up one dir, main page]

Menu

[r738]: / ihs.pas  Maximize  Restore  History

Download this file

462 lines (420 with data), 12.4 kB

  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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
{ $Id: ihs.pas 7128 2005-10-24 13:30:32Z mkaemmerer $
Copyright (C) 1991-2001 Peter Mandrella
Copyright (C) 2000-2002 OpenXP team (www.openxp.de)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
}
{$I xpdefine.inc }
{$R-,S-}
uses
{$IFDEF NCRT }
xpcurses,
{$ENDIF }
typeform,xpglobal,xp0,sysutils;
{$IFDEF Delphi}
type pathstr = string;
{$ENDIF}
const maxpages = 4096;
version = '1.23';
date = '''89-91,95,00';
obufsize = 16384;
var fname,
outpath : string;
t : text;
f : file;
pages : word;
pageadr : array[1..maxpages] of packed record
nr : smallword;
adr : longint;
end;
qvwused : array[1..maxpages] of smallword;
qvwun : smallword;
p : pointer;
// gstr muss ShortString sein wg. Assembler-Code
gstr : ShortString;
xx : byte;
obuf : array[1..obufsize] of byte;
obufp : smallword;
no_lastnext : boolean;
leermode : boolean; { vor jeder Seite eine Leerzeile einfuegen }
docode : boolean; { Text codieren }
procedure exiterr(txt:string);
begin
writeln; writeln;
writeln('Error: ',txt);
writeln('Conversion terminated.');
close(t); close(f); erase(f);
halt(1);
end;
procedure blockwf(s:string);
begin
blockwrite(f,s[1],length(s));
end;
procedure blockwfb(b:byte);
begin
blockwrite(f,b,1);
end;
procedure blockwfw(w:smallword);
begin
blockwrite(f,w,2);
end;
procedure blockwfl(l:longint);
begin
blockwrite(f,l,4);
end;
procedure blockwfill(n:longint);
var b : array[0..255] of byte;
begin
if filepos(f)<n then begin
fillchar(b,sizeof(b),0);
blockwrite(f,b,n-filepos(f));
end;
end;
procedure create_header;
var s : string;
x,y : integer;
ixp,illp : word;
flags : string;
b : byte;
dummy : longint;
begin
dummy:=0;
readln(t,s); { Name }
blockwf(#13#10+'Intelligent Help System Rel. '+version+#13#10);
blockwf('(c) '+date+' by Peter Mandrella'+#13#10);
blockwf('Help file for '+s+#13#10#$1a);
blockwfill(128);
readln(t,x,y);
blockwfb(x); blockwfb(y);
readln(t,x,y);
blockwfb(x); blockwfb(y);
blockwfw(pages);
readln(t,ixp,illp);
blockwfw(ixp); blockwfw(illp);
blockwfl(dummy); { da kommt die Index-Seiten-Adresse hin.. }
readln(t,flags); { NH = No Header = keine "Hilfe:"-Zeile }
flags:=UpperCase(flags);
b:=byte(pos('NH',flags)>0);
blockwfb(b);
b:=byte(pos('TAB',flags)>0);
blockwfb(b);
no_lastnext:=(pos('00',flags)>0);
leermode:=(pos('LEER',flags)>0);
docode:=(pos('NC',flags)=0);
blockwfb(byte(not docode));
blockwfill(160);
fillchar(pageadr,sizeof(pageadr),0);
end;
function create_page:boolean;
type za = array[1..500] of string;
var pnr,last,next,
size : word;
i,lines,p,
p1,p2,res : integer;
qvws : integer;
s,qvref,st : string;
z : ^za;
qvw : array[1..1024] of packed record
y: smallword;
x,l : byte;
nn : smallword;
end;
function nextqvref:word;
var s : string;
p : integer;
w : word;
r : integer;
begin
p:=cPos(' ',qvref);
if p=0 then
s:=qvref
else begin
s:=LeftStr(qvref,p-1);
qvref:=copy(qvref,p+1,80);
end;
val(s,w,r);
if w=0 then exiterr('Mission or illegal cross reference in page '+strs(pnr));
nextqvref:=w;
end;
function compr(s:string):string;
var p,p1 : integer;
begin
while pos(' ',s)>0 do begin
p:=pos(' ',s); p1:=p;
while (p<=length(s)) and (s[p]=' ') do inc(p);
s:=copy(s,1,p1-1)+#$1a+chr(p-p1)+copy(s,p,80);
end;
compr:=s;
end;
procedure inspage(nr:word; fpos:longint);
var p : word;
begin
inc(pages);
p:=pages;
while (p>1) and (pageadr[p-1].nr>nr) do dec(p);
if (p>1) and (pageadr[p-1].nr=nr) then
exiterr('Duplicate Page '+strs(nr));
if p<=pages then Move(pageadr[p],pageadr[p+1],6*(pages-p));
pageadr[p].nr:=nr;
pageadr[p].adr:=fpos;
end;
procedure lnerror;
begin
exiterr('Illegal/missing last/next statement');
end;
{
function sub_hgh(p:byte):byte;
var qs : string;
pp,sub : byte;
begin
if pos('<<',s)=0 then
sub_hgh:=0
else begin
qs:=s;
sub:=0;
repeat
pp:=pos('<<',qs);
if (pp>0) and (pp<p) then begin
delete(qs,pos('<<',qs),2);
inc(sub,2);
end;
until (pp=0) or (pp>=p);
repeat
pp:=pos('>>',qs);
if (pp>0) and (pp<p) then begin
delete(qs,pos('>>',qs),2);
inc(sub,2);
end;
until (pp=0) or (pp>=p);
sub_hgh:=sub;
end;
end;
}
procedure encode;
var
xorbyte: integer;
i: integer;
begin
xorbyte := xx;
for i := 1 to Length(gstr) do
begin
gstr[i] := Chr((Ord(gstr[i]) xor xorbyte) and $FF);
Inc (xorbyte, 125);
end;
xx := Byte(xorbyte and $FF);
end;
(*
procedure encode; assembler;
asm
{$IFDEF CPUX86_64 }
push rsi
lea rsi, gstr[rip]
cld
lodsb
xor rcx, rcx
mov cl, al
mov al, xx[rip]
@a: xor [rsi], al
add al, 125
inc rsi
loop @a
mov xx[rip], al
pop rsi
{$ELSE }
push esi
lea esi, gstr
cld
lodsb
xor ecx, ecx
mov cl, al
mov al, xx
@a: xor [esi], al
add al, 125
inc esi
loop @a
mov xx, al
pop esi
{$ENDIF }
end;
*)
begin { of create_page }
new(z);
readln(t,st);
val(st,pnr,res); if res<>0 then exiterr('Illegal Page number: '+st);
inspage(pnr,filepos(f));
{ write(#13,pages:4,' : ',pnr:4); }
blockwfw(pnr);
if no_lastnext then begin
last:=0; next:=0;
end else begin
readln(t,st);
if cPos(' ',st)=0 then exiterr('Illegal/missing LAST/NEXT statement');
val(LeftStr(st,cPos(' ',st)-1),last,res);
if res<>0 then exiterr('Illegal LAST statement');
val(mid(st,cPos(' ',st)+1),next,res);
if res<>0 then exiterr('Illegal NEXT statement');
end;
blockwfw(last); blockwfw(next);
if last<>0 then begin
inc(qvwun); qvwused[qvwun]:=last;
end;
if next<>0 then begin
inc(qvwun); qvwused[qvwun]:=next;
end;
if leermode then begin
lines:=1; z^[1]:='';
end else
lines:=0;
qvws:=0;
repeat
readln(t,s);
if (s<>'@') and (s<>'@@') then begin
p:=cPos('@',s);
if p>0 then if (p>1) and (s[p-1]='\') then
delete(s,p-1,1)
else begin
qvref:=copy(s,p+1,80);
s:=copy(s,1,p-1);
p1:=cPos('[',s);
while p1>0 do begin
p2:=p1+1;
while (p2<length(s)) and (s[p2]<>']') do inc(p2);
if p2-p1>2 then begin
inc(qvws);
with qvw[qvws] do begin
y:=lines+1; x:=p1{-sub_hgh(p1)}; l:=p2-p1-1;
nn:=nextqvref;
inc(qvwun);
qvwused[qvwun]:=nn;
end;
s:=copy(s,1,p1-1)+copy(s,p1+1,p2-p1-1)+copy(s,p2+1,80);
end;
inc(p1);
while (p1<length(s)) and (s[p1]<>'[') do inc(p1);
if p1=length(s) then p1:=0;
end;
end;
inc(lines);
z^[lines]:=compr(s);
end;
until (s='@') or (s='@@');
if (lines=2) and (copy(z^[2],1,2)='^^') then begin
z^[1]:=z^[2];
lines:=1;
end;
size:=0;
for i:=1 to lines do
inc(size,length(z^[i])+1);
if size=0 then exiterr('Empty page '+strs(pnr));
blockwfw(size);
blockwfb(qvws);
blockwrite(f,qvw,6*qvws);
xx:=7;
obufp:=0;
for i:=1 to lines do begin
gstr:=z^[i]+#7;
if docode then encode;
Move(gstr[1],obuf[obufp+1],length(gstr));
inc(obufp,length(gstr));
end;
blockwrite(f,obuf,obufp);
create_page:=(s<>'@@');
dispose(z);
end;
procedure testqvw;
var i,j : word;
begin
for i:=1 to qvwun do begin
j:=1;
while (j<=pages) and (pageadr[j].nr<>qvwused[i]) do inc(j);
if j>pages then exiterr('Missing Page '+strs(qvwused[i]));
end;
end;
procedure write_page_index;
var
b : array[0..511] of byte;
n : word;
adrix : longint;
begin
adrix:=filepos(f);
testqvw;
blockwrite(f,pageadr,6*pages);
n:=filepos(f)mod 512;
if n>0 then begin
fillchar(b,sizeof(b),0);
b[0]:=$1a;
blockwrite(f,b,512-n);
end;
seek(f,132); blockwfw(pages);
seek(f,138); blockwfl(adrix);
end;
var dir, name, ext : string;
begin
SetCurrentDir(StartupDir);
writeln('Intelligent Help System '+version+' (c) '+date+' Peter Mandrella (C) OpenXP Team');
write('Source File: ');
fname:=paramstr(1);
if fname='' then
readln(fname);
if FName = '' then exit;
FName := FileLowerCase(ChangeFileExt(FName, '.ihq'));
if ParamStr(1) <> '' then writeln(fname);
if not FileExists(fname) then
begin
writeln; writeln('Error: File not found.');
halt(1);
end;
getmem(p,32768);
assign(t,fname);
settextbuf(t,p^,32768);
reset(t);
outpath:='';
if paramcount=2 then
begin
outpath := paramstr(2);
if outpath <> '' then
begin
OutPath := IncludeTrailingPathDelimiter(OutPath);
fname:= ExtractFilename(fname);
end
end;
FName := FileLowerCase(OutPath + ChangeFileExt(FName, extHelp));
Writeln('Destination File: ', FName);
assign(f,fname);
rewrite(f,1);
create_header;
qvwun:=0;
pages:=0;
writeln('Processing page');
repeat until not create_page;
write_page_index;
close(t);
close(f);
writeln;
writeln('Conversion complete.');
end.
{ Aufbau des Help-Files:
128 Beschreibung mit abschliessendem cr/lf/eof
4 x,y,breite,hoehe
2 Anzahl Seiten (pg)
2 Index-Seitennr.
2 NoHelp-Seitennr.
4 Adresse der Indexliste
1 NoHead-Flag
1 TabMode-Flag
je Seite: 2 Bytes Seitenlaenge (Bytes)
n Bytes Daten (codiert)
....
pg*6 Index-Liste:
je Seite: 2 Bytes Seitennr.
4 Bytes Adresse (absolutes Dateioffset)
}