.h to .d advice needed

Emp empty at nomail.com
Mon Aug 7 03:20:49 PDT 2006


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 at mailinator.com> wrote in message 
news:eb6ton$v9q$1 at 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;
> 





More information about the Digitalmars-d-learn mailing list