[comp.sys.atari.st] saving GCC errors

rcb@netcom.UUCP (Roy Bixler) (12/17/90)

I am using GNU C inside of Gulam 1.04.05 to do some porting (of
Z-modem version 3!)  and this would be much less painful if there was
a way to save the compilation errors in a file.  I don't think GNU C
has any listing option (if so, I'd sure like to know!).  Another
method I was thinking of was to re-direct the standard error output to
a file, but apparently Gulam doesn't have that feature either.  Any
ideas?

Roy
netcom!rcb@apple.com

apratt@atari.UUCP (Allan Pratt) (12/18/90)

rcb@netcom.UUCP (Roy Bixler) writes:
>I am using GNU C inside of Gulam 1.04.05 ...
>re-direct the standard error output to a file..

Here's a program that does what you're after.  It compiles under MWC, GCC,
and Alcyon C.  It works best under Gulam because Gulam implements shell_p,
a way for a child of Gulam to say "here, Gulam, please execute this
command line for me."  It may not be the best 'c' you've seen, but it
works.

(Interesting note: the MWC executable is 3622+690+188=4500 bytes
text+data+BSS (almost all text; real small), the Alcyon C executable is
6834+1434+9124=17392 bytes (half is GEM binding BSS), and the GCC
executable is 19592+904+3812=24308 bytes (just big).  The GCC "system"
call from Bammi's library is by far the most complex; I don't know what
else makes it so much larger. I tried to use "minimal.h" for the GCC
version but it didn't work: system() must use something from main.c.)

============================== rd2.c ==============================
/*
 * perform a system() call, but first, redirect handle 2 to a file.
 * See the umsg string for usage.
 * Written by Allan Pratt of Atari Corp., Dec. 17, 1990 and placed 
 * in the public domain without any warranty, expressed or implied.
 * Your mileage may vary.
 */

#include <osbind.h>

void usage();

int
main(argc,argv)
int argc;
char *argv[];
{
	int oh2;
	int nh2;
	long err, akp_system();
	int i;
	char buf[1024];

	if (argc < 3) usage();

	oh2 = Fdup(2);
	nh2 = Fcreate(argv[1],0);
	Fforce(2,nh2);

	strcpy(buf,argv[2]);

	for (i=3; i<argc; i++) {
		strcat(buf," '");
		strcat(buf,argv[i]);
		strcat(buf,"'");
	}

	err = akp_system(buf);

	Fclose(nh2);
	Fforce(2,oh2);
	Pterm(err);
}

/*
 * system() call used below.  It checks for SHELL_P in the environment.
 * If it's there, the pointer at 0x4f6 is assumed to point to a routine
 * which will execute a command string.  If it's not, the library system()
 * is called.  AKP.
 */

long
akp_system(s)
char *s;
{
	char *ptr, *getenv();

	if (getenv("SHELL_P") != 0) {
		long oldssp = Super(0L);
		long (*shell_p)() = *(long (**)())0x4f6;
		Super(oldssp);

		return (*shell_p)(s);
	}
	else return system(s);
}

char *umsg[] = {
  "Usage: rd2 stderr_file cmd args ...",
  "",
  "Where: stderr_file is the file that stderr (handle 2) gets redirected to,",
  "cmd is the command you want to execute, and args are the arguments to that",
  "command.  You can redirect stdout from your shell, and the child's stdout",
  "will go there; don't use the same file as stderr_file, though.",
  "",
  "(This program will use shell_p a la Gulam if you setenv SHELL_P to",
  "anything, otherwise it relies on the \"system()\" call from the library",
  "you compiled with.)",
  (char *)0
};

void
usage()
{
	char **p = umsg;

	while (*p) {
		Fwrite(1,(long)strlen(*p),*p);
		Fwrite(1,2L,"\r\n");
		p++;
	}
	Pterm(-1);
}
========================= end of rd2.c =========================

ridderbusch.pad@nixdorf.com (Frank Ridderbusch, PXD-S4) (12/19/90)

>>>>> On 16 Dec 90 23:08:48 GMT, rcb@netcom.UUCP (Roy Bixler) said:


Roy> I am using GNU C inside of Gulam 1.04.05 to do some porting (of
Roy> Z-modem version 3!)  and this would be much less painful if there was
Roy> a way to save the compilation errors in a file.  I don't think GNU C
Roy> has any listing option (if so, I'd sure like to know!).  Another
Roy> method I was thinking of was to re-direct the standard error output to
Roy> a file, but apparently Gulam doesn't have that feature either.  Any
Roy> ideas?

Roy> Roy
Roy> netcom!rcb@apple.com

Here are some diffs to gcc.c, which do just what you want. I
introduced a new command line option (-z), which, when in effect,
redirects stderr to a file. If you don't have the sources, drop me a
note for the executable.

*** i:\gcc.c	Sat Mar 24 15:00:42 1990
--- gcc.c	Sun Oct  7 17:44:48 1990
***************
*** 145,150 ****
--- 145,151 ----
  #ifdef atarist
  #include <osbind.h>
  #include <ctype.h>
+ #include <fcntl.h>
  long _stksize = 8192;
  extern char *getenv();
  #endif
***************
*** 354,359 ****
--- 355,364 ----

  unsigned char vflag;

+ #ifdef atarist
+ unsigned char zflag;
+ #endif
+
  /* Name with which this program was invoked.  */

  char *programname;
***************
*** 981,991 ****
    }
  #else  /* atarist */
   {
!      char **j;

!      execution_count++;
!      j = commands[0].argv;
!      return spawnve(0, j[0], j, NULL) ? -1 : 0;
   }
  #endif /* atarist */
  }
--- 986,1019 ----
    }
  #else  /* atarist */
   {
!    char **j;
!    int errfd, ret;
!
!    execution_count++;
!    j = commands[0].argv;
!
!    if (zflag)
!      {
!        errfd = Fopen("compile.err", 2);
!        if (errfd < __SMALLEST_VALID_HANDLE)
! 	 errfd = Fcreate("compile.err", 0);
!        else
! 	 Fseek(0L, errfd, 2);
!
!        Fclose(2);
!        Fforce(2, errfd);
!        Fclose(errfd);
!      }
!
!    ret = spawnve(0, j[0], j, NULL) ? -1 : 0;
!
!    if (zflag)
!      {
!        Fclose(2);
!        Fforce(2, Fdup(1));
!      }

!    return ret;
   }
  #endif /* atarist */
  }
***************
*** 1060,1065 ****
--- 1088,1099 ----
  	      vflag++;
  	      n_switches++;
  	      break;
+ #ifdef atarist
+ 	    case 'z':
+ 	      zflag++;
+ 	      n_switches++;
+ 	      break;
+ #endif

  	    default:
  	      n_switches++;
------------------------------------------------------------
--
MfG/Regards

     /====                          Siemens Nixdorf Informationssysteme AG
    /   Ridderbusch         / ,    Heinz Nixdorf Ring
   /                       /./    4790 Paderborn, West Germany
  /=== /,== ,===/  /,==,  //     
 /    //   /   /  //   / / \    NERV:ridderbusch.pad
/    /     `==/\ /    / /   \  BTX:0525467066-0001

Email: ridderbusch.pad@nixdorf.com (America (North & South))
       ridderbusch.pad@sni.de      (Rest of world)