Sign in Join

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

Mailing lists / fpc-pascal / 2010-05

Comedi Lib Header translation, was: h2pas enum error

5 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

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

Hartmut Eilers

Hallo Pascal Hackers,

Henry Vermaak wrote
This is a function that takes an enum param and returns an enum: function comedi_set_global_oor_behavior(behavior: comedi_oor_behavior): comedi_oor_behavior;

thank you Henry, I check this out.

the comedilib.h has a "include comedi.h" statement so I guess I need to translate comedi.h to a unit comedi.pas and include it in comedilib.pas in the uses clause of the interface. Is this right ?

While trying to translate comedi.h with:

h2pas -e -D -p -w -u comedi -l comedi -o comedi.pas comedi.h

I get the messages:
at line 495 error : syntax error
at line 498 error : syntax error
Internal error 1 in line 498

comedi.h:

    494
    495 static inline unsigned NI_USUAL_PFI_SELECT(unsigned pfi_channel)
    496 {
    497         if(pfi_channel < 10)
    498                 return 0x1 + pfi_channel;
    499         else
    500                 return 0xb + pfi_channel;
    501 }

Could anybody help me, is the inline the problem ? Sorry but I have nearly no expirience in this.

Thank you
Hartmut

Reply by email

Marc Santhoff
to Hartmut Eilers
Hartmut Eilers wrote 13 lines
comedi.h: 494 495 static inline unsigned NI_USUAL_PFI_SELECT(unsigned pfi_channel) 496 { 497 if(pfi_channel < 10) 498 return 0x1 + pfi_channel; 499 else 500 return 0xb + pfi_channel; 501 } is the inline the problem ?

If it is you can resolve it using the C preprocessor using a command line similar to this one:

cpp --no-stdinc comedi.h > comedi.cpped.h

Afterwards try h2pas again.

Good luck,
Marc

Marc Santhoff

Reply by email

Hartmut Eilers

Sorry for coming back on this so late, but I was busy with other projects:

Show quoted text 29 lines
>While trying to translate comedi.h with: >h2pas -e -D -p -w -u comedi -l comedi -o comedi.pas comedi.h >I get the messages: >at line 495 error : syntax error >at line 498 error : syntax error >Internal error 1 in line 498 > comedi.h: > > 494 > 495 static inline unsigned NI_USUAL_PFI_SELECT(unsigned pfi_channel) > 496 { > 497 if(pfi_channel < 10) > 498 return 0x1 + pfi_channel; > 499 else > 500 return 0xb + pfi_channel; > 501 } > > > is the inline the problem ? If it is you can resolve it using the C preprocessor using a command line similar to this one: cpp --no-stdinc comedi.h > comedi.cpped.h Afterwards try h2pas again.

I tried the above mentioned fix with the following result:

 $ cpp --no-stdinc comedi.h
comedi.cpped.h

cc1: error: unrecognized command line option "-fno-stdinc"

This commandline option is not recognized by the compiler, hmmm.

Could anybody lend me a hand with the translation of the comedi header files ? Any hints are highly appreciated. Are there other tools I can use ? Hints on other
docs / examples ?

Thanks in advance for your help
Hartmut

Reply by email

Henry Vermaak
to Hartmut Eilers
Hartmut Eilers wrote 5 lines
$ cpp --no-stdinc comedi.h > comedi.cpped.h cc1: error: unrecognized command line option "-fno-stdinc" This commandline option is not recognized by the compiler, hmmm.

Try cpp -nostdinc. After this, comment out all of the functions in the file (just search for "return"). h2pas will then parse the file successfully, after which you can rewrite the functions you've commented out (they are simple).

Henry

Reply by email

Schindler Karl-Michael
to Hartmut Eilers: Sorry for coming back on this so late, but I was busy with other projects: I tried the…
Hartmut Eilers wrote 14 lines
> If it is you can resolve it using the C preprocessor using a command > line similar to this one: > cpp --no-stdinc comedi.h > comedi.cpped.h > Afterwards try h2pas again. I tried the above mentioned fix with the following result: $ cpp --no-stdinc comedi.h > comedi.cpped.h cc1: error: unrecognized command line option "-fno-stdinc" This commandline option is not recognized by the compiler, hmmm.

Accodring to the man page of cpp there is -nostdinc. But even after trying it, the problem remains.

Could anybody lend me a hand with the translation of the comedi header files ? Any hints are highly appreciated. Are there other tools I can use ? Hints on other docs / examples ?

h2pas only does the simple direct stuff.

All the rest needs manual replacement.

As much as I know unsigned corresponds to unsigned int. static inline seems to be the problem.

Example (line 393):

static inline unsigned NI_USUAL_PFI_SELECT(unsigned pfi_channel) {
if(pfi_channel < 10)

		return 0x1 + pfi_channel;
	else
		return 0xb + pfi_channel;

}

unsigned int NI_USUAL_PFI_SELECT(unsigned int pfi_channel);

there are about 15 similar cases. At least this gives a start.

Maybe you need a translation of the function in the implementation section.

You may also need to add functions for the macros in /* range stuff */ and /* packs and unpacks a channel/range number */

check for " { was #define dname(params) para_def_expr } " in the resulting .pp file.

Finally, I prefer to use ctypes. So, unsigned int becomes cuint, float cfloat and so on. It makes checking easier.

Michael Schindler

Reply by email