diff --git a/components/chelper/cconvert.lpi b/components/chelper/cconvert.lpi index 8d9d14c6e..f3632b324 100644 --- a/components/chelper/cconvert.lpi +++ b/components/chelper/cconvert.lpi @@ -19,6 +19,9 @@ + + + @@ -50,7 +53,7 @@ - + @@ -66,9 +69,6 @@ - - - diff --git a/components/chelper/cconvert.lpr b/components/chelper/cconvert.lpr index a3e187e20..783d9e7e8 100644 --- a/components/chelper/cconvert.lpr +++ b/components/chelper/cconvert.lpr @@ -76,14 +76,48 @@ begin end; end; +procedure PrintHelp; +begin + writeln('cconvert - c to pascal convert utility'); + writeln('possible options:'); + writeln(' -all - convert the whole header to pascal, instead of a first entity'); + writeln(' -o filename - specify the output file. if not specified, outputs to stdout'); + writeln(' -ro - prevent the configuration file from modifications (adding new types, etc)'); + writeln(' -cfg filename - specifies the configuration file'); + writeln(' -defines filename - macros definition file. should be in C-preprocessor format'); +end; + +procedure ReadParams(var InputFileName: String); +var + i : integer; + s : string; +begin + for i:=1 to ParamCount do begin + s:=LowerCase(ParamStr(i)); + if (s='-h') or (s='-help') or (s='-?') then begin + PrintHelp; + Halt; + end; + end; + InputFileName:=ParamStr(ParamCount); +end; + var inps, outs : TStringList; i : Integer; p : TPoint; cfg : TConvertSettings; err : TErrorInfo; + fn : String; begin if ParamCount=0 then Exit; + ReadParams(fn); + if not FileExists(fn) then begin + writeln('file doesn''t exist: ', fn); + Exit; + end; + + inps := TStringList.Create; outs := TStringList.Create; diff --git a/components/chelper/cparsertypes.pas b/components/chelper/cparsertypes.pas index 4b5352ae9..86b67973f 100755 --- a/components/chelper/cparsertypes.pas +++ b/components/chelper/cparsertypes.pas @@ -721,13 +721,13 @@ begin idx := Index; i := idx+1; ScanWhile(Buf, i, WhiteSpaceChars); - s := ScanTo(Buf, i, WhiteSpaceChars); - if s = 'define' then df := TCPrepDefine.Create(idx) - else if s = 'include' then df := TCPrepInclude.Create(idx) - else if s = 'else' then df := TCPrepInclude.Create(idx) - else if s = 'endif' then df := TCPrepEndif.Create(idx) - else if s = 'pragma' then df := TCPrepPragma.Create(idx) - else if (s = 'if') or (s = 'elif') or (s = 'ifdef') or (s = 'ifndef') then begin + s := ScanTo(Buf, i, SpaceEolnChars); + if s='define' then df := TCPrepDefine.Create(idx) + else if (s='include') or (s='import') then df := TCPrepInclude.Create(idx) + else if s='else' then df := TCPrepInclude.Create(idx) + else if s='endif' then df := TCPrepEndif.Create(idx) + else if s='pragma' then df := TCPrepPragma.Create(idx) + else if (s='if') or (s='elif') or (s='ifdef') or (s='ifndef') then begin df := TCPrepIf.Create(idx); TCPrepIf(df).IfOp:=s; end else @@ -739,12 +739,9 @@ begin Result := df.Parse(Self); Comments.Add(df); if Assigned(OnPrecompile) then OnPrecompile(Self, df); - end; + end else + SetError('cannot handle preprocessor: "'+s+'"'); - if not Result then begin - SetError('cannot handle preprocessor'); - Exit; - end; finally ProcessingMacro := false; end; @@ -1168,8 +1165,6 @@ begin try AParser.TokenTable.Symbols := AParser.TokenTable.Symbols + ['"']; - //i := AParser.TokenPos; - AParser.FindNextToken(s, tt); Result := (s = '"') or (s = '<'); if not Result then Exit; @@ -1182,7 +1177,6 @@ begin if (s = '/') or (s = '\') or (tt = tt_Ident) then Included := Included + s; until (tt =tt_Symbol) and ((s <> '\') or (s <> '/')); - Result := s = exp; SkipLine(AParser.buf, AParser.Index); finally @@ -1689,7 +1683,7 @@ begin Parser.NextToken; id:=ParseNamePart(Parser); ConsumeToken(Parser, ')'); - end else if Parser.TokenType=tt_Ident then begin + end else if (Parser.TokenType=tt_Ident) or (Parser.Token='^') then begin id:=TNamePart.Create(nk_Ident); id.id:=Parser.Token; Parser.NextToken;