Thread overview | |||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
August 07, 2006 .h to .d advice needed | ||||
---|---|---|---|---|
| ||||
I'm trying to translate NIDAQmx.h to a .d which D can use. But I'm not really sure whether this is usefull or not. The lib is only msvc compatible, is this a problem? I really know like null about linking (thus liking D :). If it is usefull to translate it to D, I'm afraid of this header thing. It is more than 6000 lines tall :( and, next to what is on the website, I have no clue :) simple things like: #define FOO 1 to: const int FOO = 1; Can't be done by a simple replace and manually adding the '=' is undoable for 6000 lines. Is there some program which can do these things automated? Thx for any advice/help. |
August 07, 2006 Re: .h to .d advice needed | ||||
---|---|---|---|---|
| ||||
Posted in reply to Emp | Yes, it's called "htod" and available on the digitalmars.com webpage. L. "Emp" <empty@nomail.com> wrote in message news:eb6e25$i35$1@digitaldaemon.com... > I'm trying to translate NIDAQmx.h to a .d which D can use. > But I'm not really sure whether this is usefull or not. The lib is only > msvc compatible, is this a problem? > I really know like null about linking (thus liking D :). > > If it is usefull to translate it to D, I'm afraid of this header thing. It is more than 6000 lines tall :( and, next to what is on the website, I have no clue :) > > simple things like: > > #define FOO 1 > to: > const int FOO = 1; > > Can't be done by a simple replace and manually adding the '=' is undoable > for 6000 lines. > Is there some program which can do these things automated? > Thx for any advice/help. > |
August 07, 2006 Re: .h to .d advice needed | ||||
---|---|---|---|---|
| ||||
Posted in reply to Emp | Emp wrote: ... > Is there some program which can do these things automated? > Thx for any advice/help. htod seems to be the tool you are looking for. http://www.digitalmars.com/d/htod.html While D is binary compatible with C code, it cannot compile C code nor C header files. In order for D to link with C code, the C declarations residing in C header files need to be converted to a D module. htod is a migration tool to aid in convering C header files. For people reading this thread who are not familiar with RegExps changing #define FOO 1 to const int FOO = 1; is easy if you take the time to understand how RegExp can generalize many patterns. Regular and replacement expressions should be available in any basic code editor. They are also included in Phobos in std.regex. The docs contain a link to this page which documents D's variation of regexp: http://www.digitalmars.com/ctg/regular.html Decimal constants [0-9]+ Octal Constants 0[0-9]+ Hexadecimal Constants 0[xX][0-9A-F] Variable Names start alpha or under and allow digits, '-' and '_' [a-z_][0-9a-z_-]+ They are seperated by one or more spaces or tabs [ \t]+ Putting it all together #DEFINE[ \t]+([a-z_][0-9a-z_-]+)[ \t]+(([0-9]+)|(0[0-9]+)|(0[x][0-9A-F])) Now you can search (ignoring case) and replace all those patterns with const int $1 = $2; So #DEFINE FOO 1 #DEFINE FOO-bar 010 #DEFINE FOO_baz 0x10 becomes const int FOO = 1; const int foo-bar = 010; const int __fOo_bAz = 0x10; |
August 07, 2006 Re: .h to .d advice needed | ||||
---|---|---|---|---|
| ||||
Posted in reply to nobody | nobody wrote: Horrible typo. Instead of > #DEFINE FOO_baz 0x10 ... > becomes ... > const int __fOo_bAz = 0x10; I meant #DEFINE __FOO_baz 0x10 becomes const int __FOO_baz = 0x10; Sorry! |
August 07, 2006 Re: .h to .d advice needed | ||||
---|---|---|---|---|
| ||||
Posted in reply to nobody | Thx! I did not know about these kind of search commands before :) I still think it would be a hellish job for me to do everything through search commands (I did a few :) love them regexp) H2d would be a nice help but I see it is a linux only app.(winxp here) "nobody" <nobody@mailinator.com> wrote in message news:eb6ton$v9q$1@digitaldaemon.com... > Emp wrote: > ... > >> Is there some program which can do these things automated? Thx for any advice/help. > > htod seems to be the tool you are looking for. > > http://www.digitalmars.com/d/htod.html > > While D is binary compatible with C code, it cannot compile C code nor C > header files. In order for D to link with C code, the C declarations > residing in C header files need to be converted to a D module. htod is a > migration tool to aid in convering C header files. > > For people reading this thread who are not familiar with RegExps changing > > #define FOO 1 > > to > > const int FOO = 1; > > is easy if you take the time to understand how RegExp can generalize many patterns. Regular and replacement expressions should be available in any basic code editor. They are also included in Phobos in std.regex. The docs contain a link to this page which documents D's variation of regexp: > > http://www.digitalmars.com/ctg/regular.html > > > Decimal constants > [0-9]+ > > Octal Constants > 0[0-9]+ > > Hexadecimal Constants > 0[xX][0-9A-F] > > Variable Names start alpha or under and allow digits, '-' and '_' > [a-z_][0-9a-z_-]+ > > They are seperated by one or more spaces or tabs > [ \t]+ > > Putting it all together > #DEFINE[ \t]+([a-z_][0-9a-z_-]+)[ > \t]+(([0-9]+)|(0[0-9]+)|(0[x][0-9A-F])) > > > Now you can search (ignoring case) and replace all those patterns with > const int $1 = $2; > > > So > > #DEFINE FOO 1 > #DEFINE FOO-bar 010 > #DEFINE FOO_baz 0x10 > > becomes > > const int FOO = 1; > const int foo-bar = 010; > const int __fOo_bAz = 0x10; > |
August 07, 2006 Re: .h to .d advice needed | ||||
---|---|---|---|---|
| ||||
Posted in reply to Emp | Emp wrote:
> H2d would be a nice help but I see it is a linux only app.(winxp here)
Erm, actually look again. Its a Windows only app right now. Listed under the "Bugs" header is "no Linux version yet."
-- Chris Nicholson-Sauls
|
August 07, 2006 Re: .h to .d advice needed | ||||
---|---|---|---|---|
| ||||
Posted in reply to Emp | Emp wrote:
> Thx! I did not know about these kind of search commands before :)
> I still think it would be a hellish job for me to do everything through search commands (I did a few :) love them regexp)
> H2d would be a nice help but I see it is a linux only app.(winxp here)
>
The dsource h2d project is linux only, the digitalmars h2d is windows only.
|
August 08, 2006 Re: .h to .d advice needed | ||||
---|---|---|---|---|
| ||||
Posted in reply to clayasaurus | Thx, I thought there was only one, the dsource one that is. I've succesfully run the windows version on my headerfile, but I'm a bit suspicious about the output. (cmd: 'htod NIDAQmx.h' and it should be an ANSI C header) All the error codes have been commented out: //C #define DAQmxErrorCOCannotKeepUpInHWTimedSinglePoint (-209805) And '-209805' is nowhere else to be found (in a global search). Another question(not about the header file, but some example code :) How do I translate this to D? #define DAQmxErrChk(functionCall) if( DAQmxFailed(error=(functionCall)) ) goto Error; else It is used like this: DAQmxErrChk (DAQmxCreateTask("",&taskHandle)); Thx. |
August 08, 2006 Re: .h to .d advice needed | ||||
---|---|---|---|---|
| ||||
Posted in reply to Emp | On Tue, 8 Aug 2006 02:53:18 +0200, Emp wrote: > Thx, I thought there was only one, the dsource one that is. > > I've succesfully run the windows version on my headerfile, but I'm a bit > suspicious about the output. > (cmd: 'htod NIDAQmx.h' and it should be an ANSI C header) > All the error codes have been commented out: > //C #define DAQmxErrorCOCannotKeepUpInHWTimedSinglePoint > (-209805) > And '-209805' is nowhere else to be found (in a global search). > > Another question(not about the header file, but some example code :) > How do I translate this to D? > #define DAQmxErrChk(functionCall) if( DAQmxFailed(error=(functionCall)) ) > goto Error; else > > It is used like this: > DAQmxErrChk (DAQmxCreateTask("",&taskHandle)); > > Thx. Yuck! Why do people make it hard for themselves ;-) void DAQmxErrChk( int(?) functionCall ) { if (DAQmxFailed (error = functionCall)) throw new DAQException("whatever"); } Then replace the 'Error:' label with ... scope(failure) { // Handle any exception thrown during this scope. if (error == ...) ... } -- Derek (skype: derek.j.parnell) Melbourne, Australia "Down with mediocrity!" 8/08/2006 10:56:34 AM |
August 08, 2006 Re: .h to .d advice needed | ||||
---|---|---|---|---|
| ||||
Posted in reply to Derek Parnell | Thx! Now if only I would understand why there are lines like these in the original header file: //*** Values for DAQmx_Read_WaitMode *** //*** Value set WaitMode *** #define DAQmx_Val_WaitForInterrupt 12523 // Wait For Interrupt #define DAQmx_Val_Poll 12524 // Poll #define DAQmx_Val_Yield 12525 // Yield #define DAQmx_Val_Sleep 12547 // Sleep //*** Values for DAQmx_Write_WaitMode *** //*** Value set WaitMode2 *** #define DAQmx_Val_Poll 12524 // Poll #define DAQmx_Val_Yield 12525 // Yield #define DAQmx_Val_Sleep 12547 // Sleep See the double defining. Any idea of why is this done? I just removed all the double consts, all 100 of them :/ :) > > Yuck! Why do people make it hard for themselves ;-) > > void DAQmxErrChk( int(?) functionCall ) > { > if (DAQmxFailed (error = functionCall)) > throw new DAQException("whatever"); > } > > Then replace the 'Error:' label with ... > > scope(failure) > { > // Handle any exception thrown during this scope. > if (error == ...) ... > } > > > -- > Derek > (skype: derek.j.parnell) > Melbourne, Australia > "Down with mediocrity!" > 8/08/2006 10:56:34 AM |
Copyright © 1999-2021 by the D Language Foundation