[m-dev.] for review: fixing bart's complaints about MERCURY_OPTIONS

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Aug 20 01:15:38 AEST 1998


Zoltan Somogyi, you wrote:
> 
> runtime/getopt.[ch]:
> runtime/getopt1.c:
> runtime/GETOPT:
> runtime/GETOPT/getopt.[ch]:
> runtime/GETOPT/getopt1.c:
> 	Move these files to a new subdirectory, GETOPT.

Any particular reason why the directory name is in capitals?
I think it would be more consistent with the other directory names
to make it lower-case.

> runtime/process_getopt:
> 	This is the script that creates mercury_getopt{.h,.c,1.c} from the
> 	files in GETOPT.

This is a very nice solution to the various conflicting problems
with getopt.

runtime/mercury_wrapper.c: process_options():
> +	if (MR_optind != argc) {
> +		printf("The MERCURY_OPTIONS environment variable "
> +			"contains something other than\n"
> +			"an option. Please refer to the Environment Variables "
> +			"section of the\nMercury user's guide for details.\n");
> +		fflush(stdout);
> +		exit(1);

Shouldn't that be sent to stderr instead of stdout?

I think it would be better to call fatal_error() here
rather than exit().

> Index: runtime/process_getopt
> ===================================================================
> RCS file: process_getopt
> diff -N process_getopt
> --- /dev/null	Wed May 28 10:49:58 1997
> +++ process_getopt	Sun Aug  9 18:18:29 1998
> @@ -0,0 +1,43 @@
> +#!/bin/sh
> +
> +for file in getopt.h getopt.c getopt1.c
> +do
> +	echo processing mercury_$file
> +	cp GETOPT/$file mercury_$file
> +	ex mercury_$file << END
> +	g/#include/s/getopt/mercury_getopt/
> +	g/\<getopt/s//MR_getopt/g
> +	g/\<optarg/s//MR_optarg/g
> +	g/\<optind/s//MR_optind/g
> +	g/\<opterr/s//MR_opterr/g
> +	g/\<optopt/s//MR_optopt/g
> +	g/\<option/s//MR_option/g
> +	g/\<_getopt/s//MR__getopt/g
> +	w
> +	q

It might be more portable to use `sed' rather than `ex', I think.
e.g.

	sed -e '/#include/s/getopt/mercury_getopt/' \
	    -e '/\<getopt/s//MR_getopt/g' \
	    -e '/\<optarg/s//MR_optarg/g' \
	    -e '/\<optind/s//MR_optind/g' \
	    -e '/\<opterr/s//MR_opterr/g' \
	    -e '/\<optopt/s//MR_optopt/g' \
	    -e '/\<option/s//MR_option/g' \
	    -e '/\<_getopt/s//MR__getopt/g' \
	    mercury_$file

But I don't know off-hand whether `\>' works in sed.

> +echo finalizing mercury_getopt.h
> +ex mercury_getopt.h << END
> +1i
> +#define __GNU_LIBRARY__

That might have unwanted side effects.
It would be better to change the #ifdef __GNU_LIBRARY__
to #if 1.


-- 
Fergus Henderson              | Designing grand concepts is fun;
fjh at cs.mu.oz.au               | finding nitty little bugs is just work.
http://www.cs.mu.oz.au/~fjh   | -- Brooks, in "The Mythical Man-Month".
PGP key fingerprint: 00 D7 A2 27 65 09 B6 AC  8B 3E 0F 01 E7 5D C4 3F



More information about the developers mailing list