mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-23 08:29:35 +02:00
* extractalias command, to extract the context info into alias and .h files. (request by an user)
git-svn-id: trunk@15653 -
This commit is contained in:
parent
ae7aef0861
commit
95f74fbb11
@ -50,10 +50,10 @@ type
|
||||
end;
|
||||
|
||||
|
||||
TCmdEnum = (cmdList,cmdExtract,cmdExtractall,cmdUnblock,cmdNone); // One dummy element at the end avoids rangecheck errors.
|
||||
TCmdEnum = (cmdList,cmdExtract,cmdExtractall,cmdUnblock,cmdextractalias,cmdNone); // One dummy element at the end avoids rangecheck errors.
|
||||
|
||||
Const
|
||||
CmdNames : array [TCmdEnum] of String = ('LIST','EXTRACT','EXTRACTALL','UNBLOCK','');
|
||||
CmdNames : array [TCmdEnum] of String = ('LIST','EXTRACT','EXTRACTALL','UNBLOCK','EXTRACTALIAS','');
|
||||
|
||||
var
|
||||
theopts : array[1..4] of TOption;
|
||||
@ -81,6 +81,11 @@ begin
|
||||
writeln(stderr,' unblockchm <filespec1> [filespec2] ..' );
|
||||
writeln(stderr,' Mass unblocks (XPsp2+) the relevant CHMs. Multiple files');
|
||||
writeln(stderr,' and wildcards allowed');
|
||||
writeln(stderr,' extractalias <chmfilename> [basefilename] [symbolprefix]' );
|
||||
writeln(stderr,' Extracts context info from file "chmfilename" ');
|
||||
writeln(stderr,' to a "basefilename".h and "basefilename".ali,');
|
||||
writeln(stderr,' using symbols "symbolprefix"contextnr');
|
||||
|
||||
Halt(1);
|
||||
end;
|
||||
|
||||
@ -341,6 +346,65 @@ begin
|
||||
r.free;
|
||||
end;
|
||||
|
||||
procedure ExtractAlias(filespec:TStringDynArray);
|
||||
|
||||
var s,
|
||||
chm,
|
||||
prefixfn,
|
||||
symbolname : string;
|
||||
i,cnt: integer;
|
||||
cl : TList;
|
||||
x : PcontextItem;
|
||||
f : textfile;
|
||||
fs: TFileStream;
|
||||
r : TChmReader;
|
||||
|
||||
begin
|
||||
symbolname:='helpid';
|
||||
chm:=filespec[0];
|
||||
prefixfn:=changefileext(chm,'');
|
||||
if length(filespec)>1 then
|
||||
prefixfn:=filespec[1];
|
||||
if length(filespec)>2 then
|
||||
symbolname:=filespec[2];
|
||||
|
||||
|
||||
if not Fileexists(chm) then
|
||||
begin
|
||||
writeln(stderr,' Can''t find file ',chm);
|
||||
halt(1);
|
||||
end;
|
||||
fs:=TFileStream.create(chm,fmOpenRead);
|
||||
r:=TCHMReader.create(fs,true);
|
||||
cl:=r.contextlist;
|
||||
if assigned(cl) and (cl.count>0) then
|
||||
begin
|
||||
cnt:=cl.count;
|
||||
assignfile(f,changefileext(chm,'.ali'));
|
||||
rewrite(f);
|
||||
for i:=0 to cnt-1 do
|
||||
begin
|
||||
x:=pcontextitem(cl[i]);
|
||||
s:=x^.url;
|
||||
if (length(s)>0) and (s[1]='/') then
|
||||
delete(s,1,1);
|
||||
|
||||
writeln(f,symbolname,x^.context,'=',s);
|
||||
end;
|
||||
closefile(f);
|
||||
assignfile(f,changefileext(chm,'.h'));
|
||||
rewrite(f);
|
||||
for i:=0 to cnt-1 do
|
||||
begin
|
||||
x:=pcontextitem(cl[i]);
|
||||
writeln(f,'#define ',symbolname,x^.context,' ',x^.context);
|
||||
end;
|
||||
closefile(f);
|
||||
end;
|
||||
r.free;
|
||||
end;
|
||||
|
||||
|
||||
procedure unblockchm(s:string);
|
||||
var f : file;
|
||||
begin
|
||||
@ -494,7 +558,12 @@ begin
|
||||
else
|
||||
WrongNrParam(cmdnames[cmd],length(localparams));
|
||||
end;
|
||||
|
||||
cmdextractalias: begin
|
||||
if length(localparams)>0 then
|
||||
extractalias(localparams)
|
||||
else
|
||||
WrongNrParam(cmdnames[cmd],length(localparams));
|
||||
end;
|
||||
end; {case cmd of}
|
||||
end
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user