On a subject not related to the main topic at the moment:
my tinyxlib tree just lost about 3000 lines; this was the work of a handy little tool called unifdef.
I stripped out support for a whole lot of platforms, including Windows in at least 3 variants, 16-bit systems like Win16 and DOS, two OS/2 flavors, SCO UNIX 3.2.5, SVR4, System V, Sequent, AIX, SunOS, IRIX, Lynx, QNX, OS X, HP-UX, Ultrix, pre-ANSI C, and more. I have not yet purged VMS; that is an oversight.
In summary, -DMACRO will treat MACRO as always defined and remove the ifdef wrappers to make the source consistent with that, while -UMACRO will treat MACRO as undefined and remove all code that depends on it. You need to specify -M .bak or -m for processing multiple files; -M .bak makes a backup of original.c named original.c.bak, while -m leaves no backup (which works nicely with git.)
When using unifdef, be warned: the obvious approach is WRONG.
Code: Select all
find -name '*.c' -o -name '*.h' |xargs unifdef -m -UWIN32
is what you might think is the right way.
But it will actually break any symlinks you have.
So the correct approach is:
Code: Select all
find -name '*.c' -type f -o -name '*.h' -type f |xargs unifdef -m -UWIN32 -DSTDC -D__STDC__ -Uultrix -UVMS -UDNETCONN
Further, if you run it with -UWIN32 and then with -U__EMX__, you may be surprised to find that you still have code with
Code: Select all
#if defined(WIN32) || defined(__EMX__)
This is because the first time, it only removes code that can only be reached if WIN32 is defined; the second time, it only removes code that can only be reached if __EMX__ is defined.
So be sure to append macros rather than replacing them.
While looking at this, I noticed that X_LOCALE is currently turned on; but it does not do what you might expect.
X_LOCALE means "Use internal code to duplicate setlocale() and the rest of the POSIX locale api, assuming that locales are not really supported by the OS."
I would suggest turning it off; per my tests, it seems that ABI does not break, but a rebuild against it is probably best.