[comp.windows.x] 2 small imake bugs + patch

bin@primate.wisc.edu (Brain in Neutral) (08/01/90)

[also sent to xbugs.  Todd Brunhoff says he thinks these are correct.]

VERSION:
    R4

CLIENT MACHINE and OPERATING SYSTEM:
	Irrelevant.

DISPLAY TYPE:
	Irrelevant.

WINDOW MANAGER:
	Irrelevant.

AREA:
	X configuration

SYNOPSIS:
	imake (mit/config/imake.c) has two small bugs, one related to error
	messages, another to argument processing.

DESCRIPTION:
	(1) LogFatal() tries to print the program name on an error.  The name
	is set in SetOpts().  But LogFatal() may be called from within init(),
	which is called prior to SetOpts().  This means LogFatal() might try
	to dereference a NULL pointer.  Fix:  supply default program name
	with variable declaration.

	(2) "-s file" or "-sfile" are supposed to direct output to "file".
	Both work when "file" is not "-".  Otherwise "-s-" works, "-s -"
	does not.

REPEAT BY:
	(1) Try:
		setenv IMAKEINCLUDE junk
		imake
	Result:
		(null): Environment var IMAKEINCLUDE must begin with -I
		  Stop.
	or you'll dump core.

	(2) Try:
		imake -v -T/dev/null -s -
	Result:
		./Makefile will be trashed.

----------------
Patch follows:

*** imake.c.old	Tue Jul 31 12:16:10 1990
--- imake.c	Tue Jul 31 13:04:33 1990
***************
*** 147,153 ****
  char	*Imakefile = NULL;
  char	*Makefile = "Makefile";
  char	*Template = "Imake.tmpl";
! char	*program;
  char	*FindImakefile();
  char	*ReadLine();
  char	*CleanCppInput();
--- 147,153 ----
  char	*Imakefile = NULL;
  char	*Makefile = "Makefile";
  char	*Template = "Imake.tmpl";
! char	*program = "imake";
  char	*FindImakefile();
  char	*ReadLine();
  char	*CleanCppInput();
***************
*** 319,327 ****
  		} else if (argv[0][1] == 's') {
  		    if (argv[0][2])
  			Makefile = (argv[0][2] == '-') ? NULL : argv[0]+2;
! 		    else if (argc > 1 && argv[1][0] != '-') {
  			argc--, argv++;
! 			Makefile = argv[0];
  		    }
  		    show = TRUE;
  		} else if (argv[0][1] == 'e') {
--- 319,329 ----
  		} else if (argv[0][1] == 's') {
  		    if (argv[0][2])
  			Makefile = (argv[0][2] == '-') ? NULL : argv[0]+2;
! 		    else {
  			argc--, argv++;
! 			if (! argc)
! 			    LogFatal("No description arg after -s flag\n", "");
! 			Makefile = (argv[0][0] == '-') ? NULL : argv[0];
  		    }
  		    show = TRUE;
  		} else if (argv[0][1] == 'e') {