[net.sources.d] ifdef filter

chris@umcp-cs.UUCP (07/20/86)

In article <323@enmasse.UUCP> someone writes:
>It often happens that software packages are set up to run on so many
>configurations that it is hard to read the code because of all the
>ifdefs. ... That is, filter out everything that is not going to be
>expanded by cpp while retaining the ifdefs that are going to be expanded,
>just for comment value.

I can understand the desire for this: reading code before using it
is often a good idea.  However, I am not at all convinced that this
is a good way to make the code more readable.  I have run into this
`ifdef problem' in the past, and the best solution I have come up
with so far is to properly group the dependencies and to construct
system-independent routines or `define's so that no further `if's
are required:

	#ifdef xyzzy
	#define strchr index
	#define strrchr rindex
	#define input_pending(fd) funny_system_call(fd)
	#else /* xyzzy */
	#define	input_pending(fd) routine_to_do_input_pending(fd)
	#endif /* xyzzy */

	#if defined(a) || defined(b)
	#define memcpy(d, s, n) bcopy(s, d, n)
	#endif /* a || b */

	#ifdef gleep
	routine()		/* for gleep */
	{
		...
	}
	#else /* gleep */
	routine()		/* for everyone else */
	{
		...
	}
	#endif /* gleep */

and so forth.

Of course, doing this to an existing program is much more difficult
than simply weeding out irrelevant `ifdef's.  It does, however, maintain
portability.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 1516)
UUCP:	seismo!umcp-cs!chris
CSNet:	chris@umcp-cs		ARPA:	chris@mimsy.umd.edu

loverso@sunybcs.UUCP (John Robert LoVerso) (07/20/86)

In article <323@enmasse.UUCP> someone writes:
>It often happens that software packages are set up to run on so many
>configurations that it is hard to read the code because of all the
>ifdefs. ... That is, filter out everything that is not going to be
>expanded by cpp while retaining the ifdefs that are going to be expanded,
>just for comment value.

A selective C preprocessor (scpp) was posted to mod.sources in Sept 1985.
It should be in the mod.sources archives.  It was written by Brad Needham
of Tektronix, and can be very convenient at times.

..jOhn

bradn@tekig4.UUCP (07/20/86)

In article <2389@brl-smoke.ARPA> rbj@icst-cmr (Root Boy Jim) writes:
>Berkeley 4.x has a program called unifdef. The RAND corparation has
>a program like this on their new RAND editor tape. I might be able to
>send you a copy of it if I can find a good path to you.

How quickly folks forget mod.sources.  The mod.sources archive contains
a program I wrote called "scpp" (for "Selective C PreProcessor") -- it
does exactly what you want.

Unlike "unifdef" or the Rand unifdef'er, Scpp is a complete reimplementation
of the functionality of Cpp -- it properly handles nasty problems like:

	#if defined(VAX) || BUFSIZ > 512
	....
	#endif

Brad Needham
Tektronix, Inc.
...decvax!tektronix!tekig4!bradn