2
!!! Someone please fix DRIVERS.PAS, so it doesn't clears the screen on exit
3
when we didn't use any of it's functions, just had it in 'uses'
5
Then we can delete GetDosTicks() from WHelp...
8
uses Objects,WUtils,WHelp,WTPHWriter;
19
FirstTempTopic = 1000000;
25
THCIndexEntry = record
35
PHCIndexEntryCollection = ^THCIndexEntryCollection;
36
THCIndexEntryCollection = object(T
38
var SrcName, DestName: string;
39
HelpFile : THelpFileWriter;
41
procedure Print(const S: string);
46
procedure Abort; forward;
50
Print('Syntax : TPHC <helpsource>[.TXT] <helpfile>[.FPH]');
54
procedure Fatal(const S: string);
60
procedure Warning(const S: string);
65
procedure ProcessParams;
67
if (ParamCount<1) or (ParamCount>2) then Help;
69
if ExtOf(SrcName)='' then SrcName:=SrcName+SrcExt;
71
DestName:=DirAndNameOf(SrcName)+HelpExt
74
DestName:=ParamStr(2);
75
if ExtOf(DestName)='' then DestName:=DestName+HelpExt;
79
procedure Compile(SrcS, DestS: PStream);
83
HelpFile: PHelpFileWriter;
85
NextTempTopic: longint;
86
procedure AddLine(const S: string);
89
HelpFile^.AddLineToTopic(CurTopic,S);
91
procedure ProcessToken(S: string);
95
TopicContext: THelpCtx;
99
P:=Pos(' ',S); if P=0 then P:=length(S)+1;
100
Token:=UpcaseStr(copy(S,1,P-1)); Delete(S,1,P); S:=Trim(S);
101
if Token=TokenIndex then
103
if InCode then AddLine(hscCode);
104
if copy(S,1,1)<>'{' then
105
Fatal('"{" expected at line '+IntToStr(CurLineNo));
106
if copy(S,length(S),1)<>'}' then
107
Fatal('"}" expected at line '+IntToStr(CurLineNo));
108
S:=copy(S,2,length(S)-2);
109
P:=Pos(':',S); if P=0 then P:=length(S)+1;
112
if Token=TokenTopic then
114
if InCode then AddLine(hscCode);
115
P:=Pos(' ',S); if P=0 then P:=length(S)+1;
116
TopicName:=UpcaseStr(copy(S,1,P-1)); Delete(S,1,P); S:=Trim(S);
118
Fatal('Topic name missing at line '+IntToStr(CurLineNo));
122
if copy(S,1,1)<>'=' then
124
Fatal('"=" expected at line '+IntToStr(CurLineNo));
129
S:=Trim(copy(S,2,255));
130
TopicContext:=StrToInt(S);
131
if LastStrToIntResult<>0 then
132
Fatal('Error interpreting context number at line '+IntToStr(CurLineNo));
134
if TopicContext=0 then
136
TopicContext:=NextTempTopic;
139
CurTopic:=HelpFile^.CreateTopic(TopicContext);
141
if Token=TokenCode then
146
Warning('Uknown token "'+Token+'" encountered at line '+IntToStr(CurLineNo));
148
procedure ProcessLine(const S: string);
152
function ReadNextLine: boolean;
159
if (C in[CR,LF])=false then
161
until (C=LF) or (SrcS^.Status<>stOK);
162
ReadNextLine:=(SrcS^.Status=stOK);
166
New(HelpFile, InitStream(DestS,0));
167
CurTopic:=nil; CurLineNo:=0;
168
NextTempTopic:=FirstTempTopic;
173
if copy(CurLine,1,length(CommentPrefix))=CommentPrefix then
176
if copy(CurLine,1,length(TokenPrefix))=TokenPrefix then
177
ProcessToken(copy(CurLine,2,255))
181
ProcessLine(CurLine);
184
if HelpFile^.WriteFile=false then
185
Fatal('Error writing help file.');
186
Dispose(HelpFile, Done);
189
const SrcS : PBufStream = nil;
190
DestS : PBufStream = nil;
194
if SrcS<>nil then Dispose(SrcS, Done); SrcS:=nil;
195
if DestS<>nil then Dispose(DestS, Done); DestS:=nil;
199
Print('� Help Compiler Version 0.9 Copyright (c) 1999 by B�rczi G�bor');
201
New(SrcS, Init(SrcName, stOpenRead, 4096));
202
if (SrcS=nil) or (SrcS^.Status<>stOK) then
203
Fatal('Error opening source file.');
204
New(DestS, Init(DestName, stCreate, 4096));
205
if (DestS=nil) or (DestS^.Status<>stOK) then
206
Fatal('Error creating destination file.');