Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2011-10

Error when translating a C header

4 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Luciano de Souza

Hi listers,

I tried to translate a C header with:

h2pas -e -d -p iupkey.h

I got the following error:

at line 21 error : syntax error
at line 41 error : syntax error
Illegal character in line 45
"#define K_at '@' /* 64 */"
Illegal character in line 73
"#define K_backslash '\\' /* 92 */"
Illegal character in line 73
"#define K_backslash '\\' /* 92 */"
Illegal character in line 75
"#define K_circum '^' /* 94 */"
Illegal character in line 77
"#define K_grave '`' /* 96 */"
Illegal character in line 113
"#define K_BS '\b' /* 8 */"
Illegal character in line 114
"#define K_TAB '\t' /* 9 */"
Illegal character in line 115
"#define K_LF '\n' /* 10 (0x0A) not a real key, is a combination of CR with a modifier, just to document */" Illegal character in line 116
"#define K_CR '\r' /* 13 (0x0D) */"
LexLib: yytext overflow

I could understand if the Pascal unit was generated, but not compiled. What I can't understand is that even the Pascal unit, h2pas was not able to produce.

I am trying to translate it becouse it is very important for me. Actually, I don't know C, but I hope I can complete the task.

I am blind and I am trying to create graphical interfaces. It seems to be so curious, but I can make sure the idea is reasonable and suitable. Of course, I cwon't conceive beautiful interfaces. But with the help of IUP, a graphical interface library which supports automatic layout, I will produce dialogs interacting very good with screen readers.

As my objective is to program to blind people, beauty is not properly a requirement. Having used IUP with Lua, I know it works, but now, to use it with Pascal, I need to overcome this initial difficulties.

Does someone know how to convert it? Why the unit, even wrong, is not created?

Luciano

Ludo Brands
to Luciano de Souza

The problem is in line 20: replace
#define K_apostrophe '\'' /* 39 */
with
#define K_apostrophe ' ' /* 39 */
and h2pas will create iupkey.pp. Then, in iupkey.pp replace K_apostrophe = ' ' with K_apostrophe = ''''
The problems aren't over yet. You'll need to replace K_quotedbl = '\"' with K_quotedbl = '"' as well as other escaped characters such as K_backslash, K_BS, etc. C escapes special characters with "\".
The main problem is that C mixes chars and integers freely while pascal can't do that. So the functions generated for IUPcxCODE, etc won't work. You'll need to check in IUP how the character codes are used, as characters or as integers. Only then can the header file be translated.

Ludo

Show quoted text 69 lines
-----Message d'origine----- De : De la part de Luciano de Souza Envoyé : mardi 4 octobre 2011 03:12 À : Objet : [fpc-pascal] Error when translating a C header Hi listers, I tried to translate a C header with: h2pas -e -d -p iupkey.h I got the following error: at line 21 error : syntax error at line 41 error : syntax error Illegal character in line 45 "#define K_at '@' /* 64 */" Illegal character in line 73 "#define K_backslash '\\' /* 92 */" Illegal character in line 73 "#define K_backslash '\\' /* 92 */" Illegal character in line 75 "#define K_circum '^' /* 94 */" Illegal character in line 77 "#define K_grave '`' /* 96 */" Illegal character in line 113 "#define K_BS '\b' /* 8 */" Illegal character in line 114 "#define K_TAB '\t' /* 9 */" Illegal character in line 115 "#define K_LF '\n' /* 10 (0x0A) not a real key, is a combination of CR with a modifier, just to document */" Illegal character in line 116 "#define K_CR '\r' /* 13 (0x0D) */" LexLib: yytext overflow I could understand if the Pascal unit was generated, but not compiled. What I can't understand is that even the Pascal unit, h2pas was not able to produce. I am trying to translate it becouse it is very important for me. Actually, I don't know C, but I hope I can complete the task. I am blind and I am trying to create graphical interfaces. It seems to be so curious, but I can make sure the idea is reasonable and suitable. Of course, I cwon't conceive beautiful interfaces. But with the help of IUP, a graphical interface library which supports automatic layout, I will produce dialogs interacting very good with screen readers. As my objective is to program to blind people, beauty is not properly a requirement. Having used IUP with Lua, I know it works, but now, to use it with Pascal, I need to overcome this initial difficulties. Does someone know how to convert it? Why the unit, even wrong, is not created? Luciano
Luciano de Souza
to Ludo Brands

It's almost unblievable, but with your tip, I need to solve one line to compile 3744 lines!

iupkey.pp(248,25) Error: Illegal expression
isxkey = iup_isXkey;

Do you have any idea why this error comes up?

Ludo Brands wrote 88 lines
The problem is in line 20: replace #define K_apostrophe '\'' /* 39 */ with #define K_apostrophe ' ' /* 39 */ and h2pas will create iupkey.pp. Then, in iupkey.pp replace K_apostrophe = ' ' with K_apostrophe = '''' The problems aren't over yet. You'll need to replace K_quotedbl = '\"' with K_quotedbl = '"' as well as other escaped characters such as K_backslash, K_BS, etc. C escapes special characters with "\". The main problem is that C mixes chars and integers freely while pascal can't do that. So the functions generated for IUPcxCODE, etc won't work. You'll need to check in IUP how the character codes are used, as characters or as integers. Only then can the header file be translated. Ludo > -----Message d'origine----- > De : > De la part > de Luciano de Souza > Envoyé : mardi 4 octobre 2011 03:12 > À : > Objet : [fpc-pascal] Error when translating a C header > > > Hi listers, > > I tried to translate a C header with: > > h2pas -e -d -p iupkey.h > > I got the following error: > > at line 21 error : syntax error > at line 41 error : syntax error > Illegal character in line 45 > "#define K_at '@' /* 64 */" > Illegal character in line 73 > "#define K_backslash '\\' /* 92 */" > Illegal character in line 73 > "#define K_backslash '\\' /* 92 */" > Illegal character in line 75 > "#define K_circum '^' /* 94 */" > Illegal character in line 77 > "#define K_grave '`' /* 96 */" > Illegal character in line 113 > "#define K_BS '\b' /* 8 */" > Illegal character in line 114 > "#define K_TAB '\t' /* 9 */" > Illegal character in line 115 > "#define K_LF '\n' /* 10 (0x0A) not a real key, is a > combination of CR with a modifier, just to document */" > Illegal character in line 116 > "#define K_CR '\r' /* 13 (0x0D) */" > LexLib: yytext overflow > > I could understand if the Pascal unit was generated, but not > compiled. > What I can't understand is that even the Pascal unit, h2pas > was not able > to produce. > > I am trying to translate it becouse it is very important for me. > Actually, I don't know C, but I hope I can complete the task. > > I am blind and I am trying to create graphical interfaces. It > seems to > be so curious, but I can make sure the idea is reasonable and > suitable. > Of course, I cwon't conceive beautiful interfaces. But with > the help of > IUP, a graphical interface library which supports automatic layout, I > will produce dialogs interacting very good with screen readers. > > As my objective is to program to blind people, beauty is not > properly a > requirement. Having used IUP with Lua, I know it works, but > now, to use > it with Pascal, I need to overcome this initial difficulties. > > Does someone know how to convert it? Why the unit, even wrong, is not > created? > > Luciano > _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Ludo Brands
to Luciano de Souza

iup_isXkey is a C macro that is translated by h2pas into a function. You can't assign a function to a const.

Delete line 248 and insert at line 258 the following ( just after function iup_isXkey(_c : longint) : longint; ) :

function isxkey (_c : longint) : longint;
Begin
  Result:=iup_isXkey(_c);
End;

Ludo

Show quoted text 19 lines
-----Message d'origine----- De : De la part de Luciano de Souza Envoyé : mercredi 5 octobre 2011 01:28 À : FPC-Pascal users discussions Objet : Re: RE : [fpc-pascal] Error when translating a C header It's almost unblievable, but with your tip, I need to solve one line to compile 3744 lines! iupkey.pp(248,25) Error: Illegal expression isxkey = iup_isXkey; Do you have any idea why this error comes up?