mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-28 21:20:29 +02:00
+ .rc support added by Yuri Prokushev
This commit is contained in:
parent
d605448715
commit
352350e524
103
utils/rstconv.pp
103
utils/rstconv.pp
@ -2,7 +2,7 @@
|
|||||||
$Id$
|
$Id$
|
||||||
This file is part of the Free Pascal run time library.
|
This file is part of the Free Pascal run time library.
|
||||||
Copyright (c) 1999-2000 by Sebastian Guenther
|
Copyright (c) 1999-2000 by Sebastian Guenther
|
||||||
Added OS/2 support in 2002 by Yuri Prokushev
|
Added .rc and OS/2 MSG support in 2002 by Yuri Prokushev
|
||||||
|
|
||||||
.rst resource string table file converter.
|
.rst resource string table file converter.
|
||||||
|
|
||||||
@ -30,11 +30,16 @@ resourcestring
|
|||||||
' -o file Write output to specified file (REQUIRED)'+LineEnding+
|
' -o file Write output to specified file (REQUIRED)'+LineEnding+
|
||||||
' -f format Specifies the output format:'+LineEnding+
|
' -f format Specifies the output format:'+LineEnding+
|
||||||
' po GNU gettext .po (portable) format (DEFAULT)'+LineEnding+
|
' po GNU gettext .po (portable) format (DEFAULT)'+LineEnding+
|
||||||
' msg IBM OS/2 MSG file format'+LineEnding+LineEnding+
|
' msg IBM OS/2 MSG file format'+LineEnding+
|
||||||
|
' rc Resource compiler .rc format'+LineEnding+LineEnding+
|
||||||
'OS/2 MSG file only options are:'+LineEnding+
|
'OS/2 MSG file only options are:'+LineEnding+
|
||||||
' -c identifier Specifies the component identifier (REQUIRED).'+LineEnding+
|
' -c identifier Specifies the component identifier (REQUIRED).'+LineEnding+
|
||||||
' Identifier is any three chars in upper case.'+LineEnding+
|
' Identifier is any three chars in upper case.'+LineEnding+
|
||||||
' -n number Specifies the first message number [1-9999] (OPTIONAL).'+LineEnding;
|
' -n number Specifies the first message number [1-9999] (OPTIONAL).'+LineEnding+LineEnding+
|
||||||
|
'Resource compiler script only options are:'+LineEnding+
|
||||||
|
' -s Use STRINGTABLE instead of MESSAGETABLE'+LineEnding+
|
||||||
|
' -c identifier Use identifier as ID base (ID+n) (OPTIONAL)'+LineEnding+
|
||||||
|
' -n number Specifies the first ID number (OPTIONAL)'+LineEnding;
|
||||||
|
|
||||||
|
|
||||||
InvalidOption = 'Invalid option - ';
|
InvalidOption = 'Invalid option - ';
|
||||||
@ -56,8 +61,9 @@ type
|
|||||||
var
|
var
|
||||||
InFilename, OutFilename: String;
|
InFilename, OutFilename: String;
|
||||||
ConstItems: TCollection;
|
ConstItems: TCollection;
|
||||||
Identifier: String[3];
|
Identifier: String;
|
||||||
FirstMessage: Word;
|
FirstMessage: Word;
|
||||||
|
MessageTable: Boolean;
|
||||||
|
|
||||||
procedure ReadRSTFile;
|
procedure ReadRSTFile;
|
||||||
var
|
var
|
||||||
@ -158,6 +164,68 @@ begin
|
|||||||
Close(f);
|
Close(f);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
// This routine stores rst file in rc format. Can be written as MESSAGETABLE
|
||||||
|
// as STRINGTABLE. Beware! OS/2 RC doesn't support lines longer whan 255 chars.
|
||||||
|
procedure ConvertToRC;
|
||||||
|
var
|
||||||
|
i, j: Integer;
|
||||||
|
f: Text;
|
||||||
|
item: TConstItem;
|
||||||
|
s: String;
|
||||||
|
c: Char;
|
||||||
|
|
||||||
|
begin
|
||||||
|
Assign(f, OutFilename);
|
||||||
|
Rewrite(f);
|
||||||
|
|
||||||
|
If MessageTable then
|
||||||
|
WriteLn(F, 'MESSAGETABLE')
|
||||||
|
else
|
||||||
|
WriteLn(F, 'STRINGTABLE');
|
||||||
|
|
||||||
|
WriteLn(F, 'BEGIN');
|
||||||
|
If Identifier<>'' then WriteLn(F, '#define ', Identifier);
|
||||||
|
|
||||||
|
for i := 0 to ConstItems.Count - 1 do begin
|
||||||
|
item := TConstItem(ConstItems.items[i]);
|
||||||
|
|
||||||
|
// Convert string to C-style syntax
|
||||||
|
s := '';
|
||||||
|
for j := 1 to Length(item.Value) do begin
|
||||||
|
c := item.Value[j];
|
||||||
|
case c of
|
||||||
|
#9: s := s + '\t';
|
||||||
|
#10: s := s + '\n"'#13#10'"';
|
||||||
|
{$IFNDEF UNIX}
|
||||||
|
#13: ;
|
||||||
|
#1..#8, #11..#12, #14..#31, #128..#255:
|
||||||
|
{$ELSE}
|
||||||
|
#1..#8, #11..#31, #128..#255:
|
||||||
|
{$ENDIF}
|
||||||
|
s := s + '\' +
|
||||||
|
Chr(Ord(c) shr 6 + 48) +
|
||||||
|
Chr((Ord(c) shr 3) and 7 + 48) +
|
||||||
|
Chr(Ord(c) and 7 + 48);
|
||||||
|
'\': s := s + '\\';
|
||||||
|
'"': s := s + '\"';
|
||||||
|
else s := s + c;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
// Write msg entry
|
||||||
|
WriteLn(f, '/* ', item.ModuleName, ':', item.ConstName, '*/');
|
||||||
|
WriteLn(f, '/* ', s, ' */');
|
||||||
|
If Identifier<>'' then Write(F, Identifier, '+');
|
||||||
|
WriteLn(f, I+FirstMessage,' "', s, '"');
|
||||||
|
WriteLn(f);
|
||||||
|
end;
|
||||||
|
|
||||||
|
WriteLn(F, 'END');
|
||||||
|
Close(f);
|
||||||
|
end;
|
||||||
|
|
||||||
|
// This routine stores rst file in OS/2 msg format. This format is preffered
|
||||||
|
// for help screens, messages, etc.
|
||||||
procedure ConvertToOS2MSG;
|
procedure ConvertToOS2MSG;
|
||||||
var
|
var
|
||||||
i, j: Integer;
|
i, j: Integer;
|
||||||
@ -171,6 +239,8 @@ begin
|
|||||||
Halt(1);
|
Halt(1);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Identifier:=Copy(UpperCase(Identifier), 1, 3);
|
||||||
|
|
||||||
Assign(f, OutFilename);
|
Assign(f, OutFilename);
|
||||||
Rewrite(f);
|
Rewrite(f);
|
||||||
|
|
||||||
@ -200,14 +270,13 @@ begin
|
|||||||
|
|
||||||
// Write msg entry
|
// Write msg entry
|
||||||
WriteLn(f, ';', item.ModuleName, '.', item.ConstName);
|
WriteLn(f, ';', item.ModuleName, '.', item.ConstName);
|
||||||
WriteLn(f, Format(';%s%.4d: %s %%0',[Identifier, i+FirstMessage, s]));
|
WriteLn(f, Format(';%s%.4dP: %s %%0',[Identifier, i+FirstMessage, s]));
|
||||||
WriteLn(f, Format('%s%.4dP: %s %%0',[Identifier, i+FirstMessage, Item.Value]));
|
WriteLn(f, Format('%s%.4dP: %s %%0',[Identifier, i+FirstMessage, Item.Value]));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Close(f);
|
Close(f);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
type
|
type
|
||||||
TConversionProc = procedure;
|
TConversionProc = procedure;
|
||||||
var
|
var
|
||||||
@ -225,6 +294,7 @@ begin
|
|||||||
OutputFormat:='';
|
OutputFormat:='';
|
||||||
Identifier:='';
|
Identifier:='';
|
||||||
FirstMessage:=0;
|
FirstMessage:=0;
|
||||||
|
MessageTable:=True;
|
||||||
|
|
||||||
i := 1;
|
i := 1;
|
||||||
while i <= ParamCount do begin
|
while i <= ParamCount do begin
|
||||||
@ -252,6 +322,9 @@ begin
|
|||||||
else if ParamStr(i + 1) = 'msg' then begin
|
else if ParamStr(i + 1) = 'msg' then begin
|
||||||
OutputFormat:='msg';
|
OutputFormat:='msg';
|
||||||
ConversionProc := @ConvertToOS2MSG;
|
ConversionProc := @ConvertToOS2MSG;
|
||||||
|
end else if ParamStr(i + 1) = 'rc' then begin
|
||||||
|
OutputFormat:='rc';
|
||||||
|
ConversionProc := @ConvertToRC;
|
||||||
end else begin
|
end else begin
|
||||||
WriteLn(StdErr, InvalidOutputFormat, ParamStr(i + 1));
|
WriteLn(StdErr, InvalidOutputFormat, ParamStr(i + 1));
|
||||||
Halt(1);
|
Halt(1);
|
||||||
@ -262,8 +335,15 @@ begin
|
|||||||
WriteLn(StdErr, OptionAlreadySpecified, '-c');
|
WriteLn(StdErr, OptionAlreadySpecified, '-c');
|
||||||
Halt(1);
|
Halt(1);
|
||||||
end;
|
end;
|
||||||
Identifier:=Copy(UpperCase(ParamStr(i+1)), 1, 3);
|
Identifier:=ParamStr(i+1);
|
||||||
Inc(i, 2);
|
Inc(i, 2);
|
||||||
|
end else if ParamStr(i) = '-s' then begin
|
||||||
|
if not MessageTable then begin
|
||||||
|
WriteLn(StdErr, OptionAlreadySpecified, '-s');
|
||||||
|
Halt(1);
|
||||||
|
end;
|
||||||
|
MessageTable:=False;
|
||||||
|
Inc(i);
|
||||||
end else if ParamStr(i) = '-n' then begin
|
end else if ParamStr(i) = '-n' then begin
|
||||||
if FirstMessage <> 0 then begin
|
if FirstMessage <> 0 then begin
|
||||||
WriteLn(StdErr, OptionAlreadySpecified, '-n');
|
WriteLn(StdErr, OptionAlreadySpecified, '-n');
|
||||||
@ -271,7 +351,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
try
|
try
|
||||||
FirstMessage := StrToInt(ParamStr(i + 1));
|
FirstMessage := StrToInt(ParamStr(i + 1));
|
||||||
If (FirstMessage<1) or (FirstMessage>9999) then raise EConvertError.Create(InvalidRange+' '+ParamStr(i+1));
|
If (FirstMessage<1) then raise EConvertError.Create(InvalidRange+' '+ParamStr(i+1));
|
||||||
except
|
except
|
||||||
on EConvertError do
|
on EConvertError do
|
||||||
begin
|
begin
|
||||||
@ -286,7 +366,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
If (OutputFormat<>'msg') and ((Identifier<>'') or (FirstMessage<>0)) then begin
|
If ((OutputFormat<>'msg') and (OutputFormat<>'rc')) and ((Identifier<>'') or (FirstMessage<>0)) then begin
|
||||||
WriteLn(StdErr, InvalidOption, '');
|
WriteLn(StdErr, InvalidOption, '');
|
||||||
Halt(1);
|
Halt(1);
|
||||||
end;
|
end;
|
||||||
@ -311,7 +391,10 @@ end.
|
|||||||
|
|
||||||
{
|
{
|
||||||
$Log$
|
$Log$
|
||||||
Revision 1.4 2002-09-22 10:58:25 hajny
|
Revision 1.5 2002-09-30 21:01:37 hajny
|
||||||
|
+ .rc support added by Yuri Prokushev
|
||||||
|
|
||||||
|
Revision 1.4 2002/09/22 10:58:25 hajny
|
||||||
+ support of IBM MSG files added by Yuri Prokushev
|
+ support of IBM MSG files added by Yuri Prokushev
|
||||||
|
|
||||||
Revision 1.3 2002/09/07 15:40:31 peter
|
Revision 1.3 2002/09/07 15:40:31 peter
|
||||||
|
Loading…
Reference in New Issue
Block a user