H to D with sed
Converting C header files
This is how I converted the header files for libgii.
1. Figure out what files you need to convert. Start with the top level library include (in my case gii.h).
You can use cpp to extract the dependencies (sub include files needed).
![]() |
|
I just walked through them by hand. I determined that I need:
gii.h gii-defs.h events.h system.h keyboard.h
2. Copy all these files to a working directory
![]() |
|
3. Modify includes to be local and ignore system includes. (I learned how to use regular expressions and sed during the course of this project. Wow, where have you been all my life sweet little thing.)
My sed script looks like: gii.sed
![]() |
|
It converts #include <ggi/filename.h> to #include "filename.h"
![]() |
|
Now when I run
![]() |
|
4. Convert #defines to const expressions
h2d.sed
![]() |
|
![]() |
|
5. Repair file by hand
open your .h files and fix it. In my case there were a lot of #defines for version control. I didn't need any of them so I removed them. I also had to convert some define functions. These you can safely wait to do untill after using deeify in step 6.
6. Use h2d to convert typedefs and structs
Run deeify (from dsource.org/h2d/)
I changed the gcc call in the script to keep comments (-C).
![]() |
|
7. Fix the .d file Convert the define functions. If it is a define for use in user code, I convert it to a regular function. If it is a define for readibility in the include file, we use a template.
---
Hope this helps.
For this library, 3000 lines of include file defines that I did not have to fix line by line. (And shame on the developers of ggi for being so silly with their include files)
-TravelerHauptman