.h to .d advice needed

nobody nobody at mailinator.com
Mon Aug 7 01:32:14 PDT 2006

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.


   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 

   #define FOO 1


   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:


Decimal constants

Octal Constants

Hexadecimal Constants

Variable Names start alpha or under and allow digits, '-' and '_'

They are seperated by one or more spaces or tabs
   [ \t]+

Putting it all together
   #DEFINE[ \t]+([a-z_][0-9a-z_-]+)[ 

Now you can search (ignoring case) and replace all those 
patterns with
   const int $1 = $2;


   #DEFINE     FOO    1
   #DEFINE FOO-bar  010
   #DEFINE FOO_baz 0x10


   const int FOO = 1;
   const int foo-bar = 010;
   const int __fOo_bAz = 0x10;

More information about the Digitalmars-d-learn mailing list