[comp.binaries.ibm.pc.d] Patch #1 to Gnu Awk 2.10

seg@smsdpg.uu.net (Scott Garfinkle) (04/27/89)

From article <KPETERSEN.12486014569.BABYL@WSMR-SIMTEL20.ARMY.MIL>, by w8sdz@WSMR-SIMTEL20.ARMY.MIL (Keith Petersen):
> The GNU project has just released their official MS-DOS version of
> GAWK 2.10.  It is now available from Simtel20.

Apropos to this, I am posting a PC_specific patch to gawk 2.10.
This patch, courtesy of Kent Williams (williams@umaxc.weeg.uiowa.edu),
implements the pipe ('|') operator on the PC.  It is an official patch and
brings gawk to v2.10.1.

	Scott E. Garfinkle
	SMS Data Products Group, Inc.
	uunet!smsdpg!seg (seg@smsdpg.uu.net)
----- cut here -------
#! /bin/sh
# This is a shell archive.  Remove anything before this line, then feed it
# into a shell via "sh file" or similar.  To overwrite existing files,
# type "sh file -c".
# The shar that generated this appeared in the comp.sources.unix newsgroup;
# send mail to comp-sources-unix@uunet.uu.net if you want that tool.
# If this archive is complete, you will see the following message at the end:
#		"End of shell archive."
# Contents:  ppatch popen.c popen.h
# Wrapped by seg@smsdpg on Thu Apr 13 18:20:01 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'ppatch' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'ppatch'\"
else
echo shar: Extracting \"'ppatch'\" \(6430 characters\)
sed "s/^X//" >'ppatch' <<'END_OF_FILE'
X*** Makefile	Thu Apr 13 18:14:56 1989
X--- old/Makefile	Wed Apr  5 11:58:00 1989
X***************
X*** 39,45 ****
X  #LINKFLAGS= /CO /NOE /NOI /st:0x1800
X  OPTIMIZE= -AL -Ox
X  DEBUG=#-DDEBUG #-DFUNC_TRACE -DMEMDEBUG
X! DEBUGGER=# -Zi -Od
X  PROFILE=#-pg
X  SYSV=
X  BSD=#-DHASDOPRNT
X--- 39,45 ----
X  #LINKFLAGS= /CO /NOE /NOI /st:0x1800
X  OPTIMIZE= -AL -Ox
X  DEBUG=#-DDEBUG #-DFUNC_TRACE -DMEMDEBUG
X! DEBUGGER= #-Zi
X  PROFILE=#-pg
X  SYSV=
X  BSD=#-DHASDOPRNT
X***************
X*** 50,63 ****
X  CFLAGS= $(FLAGS) $(DEBUGGER) $(PROFILE) 
X  LDFLAGS= #-Bstatic
X  
X! SRC =	awk1.c awk2.c awk3.c awk4.c awk5.c popen.c\
X  	awk6.c awk7.c awk8.c awk9.c regex.c version.c do_free.c awka.c
X  
X  PCSTUFF= makefile.pc names.lnk random.c
X  
X  AWKOBJS = awk1.obj awk2.obj awk3.obj awk4.obj awk5.obj awk6.obj awk7.obj \
X! 	  awk8.obj awk9.obj popen.obj \
X! 	  version.obj awka.obj # do_free.obj # used for MEMDEBUG
X  ALLOBJS = $(AWKOBJS) awk_tab.obj
X  
X  # Parser to use on grammar -- if you don't have bison use the first one
X--- 50,62 ----
X  CFLAGS= $(FLAGS) $(DEBUGGER) $(PROFILE) 
X  LDFLAGS= #-Bstatic
X  
X! SRC =	awk1.c awk2.c awk3.c awk4.c awk5.c \
X  	awk6.c awk7.c awk8.c awk9.c regex.c version.c do_free.c awka.c
X  
X  PCSTUFF= makefile.pc names.lnk random.c
X  
X  AWKOBJS = awk1.obj awk2.obj awk3.obj awk4.obj awk5.obj awk6.obj awk7.obj \
X! 	  awk8.obj awk9.obj version.obj awka.obj # do_free.obj # used for MEMDEBUG
X  ALLOBJS = $(AWKOBJS) awk_tab.obj
X  
X  # Parser to use on grammar -- if you don't have bison use the first one
X***************
X*** 107,113 ****
X  # this kludge necessary because MSC 5.1 compiler bombs with -Oa or -Ol (where
X  # -Ox == "-Oailt -Gs")
X  regex.obj: regex.c
X! 	$(CC) -c -Oit -AL $(DEBUGGER) regex.c
X  
X  $(AWKOBJS): awk.h
X  
X--- 106,112 ----
X  # this kludge necessary because MSC 5.1 compiler bombs with -Oa or -Ol (where
X  # -Ox == "-Oailt -Gs")
X  regex.obj: regex.c
X! 	$(CC) -c -Oit -AL regex.c
X  
X  $(AWKOBJS): awk.h
X  
X*** names.lnk	Thu Apr 13 18:15:39 1989
X--- old/names.lnk	Thu Apr 13 18:15:21 1989
X***************
X*** 11,17 ****
X  version.obj+
X  awk_tab.obj+
X  regex.obj+
X- popen.obj+
X  random.obj+
X  setargv.obj+
X  getopt.obj
X--- 11,16 ----
X*** awk.h	Thu Apr 13 16:59:14 1989
X--- old/awk.h	Wed Apr  5 11:57:58 1989
X***************
X*** 211,217 ****
X  #endif
X  
X  #ifdef __STDC__
X! extern void *malloc(unsigned), *realloc(void *, unsigned);
X  extern void free(char *);
X  extern char *getenv(char *);
X  
X--- 211,217 ----
X  #endif
X  
X  #ifdef __STDC__
X! extern char *malloc(unsigned), *realloc(char *, unsigned);
X  extern void free(char *);
X  extern char *getenv(char *);
X  
X*** awk.y	Thu Apr 13 16:59:15 1989
X--- old/awk.y	Wed Apr  5 11:57:54 1989
X***************
X*** 1076,1082 ****
X   * passed as a command line argument and writes it to a temp file. Otherwise
X   * the file name is made available in an external variable.
X   */
X! #line 1080 "awk.y"
X  static int
X  yylex()
X  {
X--- 1076,1082 ----
X   * passed as a command line argument and writes it to a temp file. Otherwise
X   * the file name is made available in an external variable.
X   */
X! 
X  static int
X  yylex()
X  {
X***************
X*** 1588,1606 ****
X  			return (fp);
X  
X  		/* no luck, keep going */
X! 		if(*awkpath)
X! 			awkpath++;	/* skip colon */
X  	} while (*awkpath);
X- #ifdef MSDOS
X- /*
X- ** under DOS (and probably elsewhere) you might have one of the awk paths
X- ** defined, WITHOUT the current working directory in it.  Therefore you
X- ** should try to open the file in the current directory
X- */
X- 	return fdopen(devopen(file,"r"),"r");
X- #else
X  	return (NULL);
X- #endif
X  }
X  
X  static NODE *
X--- 1588,1596 ----
X  			return (fp);
X  
X  		/* no luck, keep going */
X! 		awkpath++;	/* skip colon */
X  	} while (*awkpath);
X  	return (NULL);
X  }
X  
X  static NODE *
X*** awk1.c	Thu Apr 13 16:59:06 1989
X--- old/awk1.c	Wed Apr  5 11:52:54 1989
X***************
X*** 236,242 ****
X  #endif
X  
X  #ifdef MSDOS
X! #define TEMPLATE	"%s/gaXXXXXX"
X  #else
X  #define TEMPLATE	"/tmp/gawk.XXXXX"
X  #endif
X--- 236,242 ----
X  #endif
X  
X  #ifdef MSDOS
X! #define TEMPLATE	"%s/gaXXXXXX.tmp"
X  #else
X  #define TEMPLATE	"/tmp/gawk.XXXXX"
X  #endif
X*** awk7.c	Thu Apr 13 16:59:11 1989
X--- old/awk7.c	Wed Apr  5 11:57:02 1989
X***************
X*** 25,33 ****
X  
X  #include "awk.h"
X  #include <fcntl.h>
X! #if defined(MSDOS)
X! #include "popen.h"
X! #endif
X  extern NODE *concat_exp();
X  
X  static void do_file();
X--- 25,31 ----
X  
X  #include "awk.h"
X  #include <fcntl.h>
X! 
X  extern NODE *concat_exp();
X  
X  static void do_file();
X***************
X*** 856,861 ****
X--- 854,860 ----
X  	case Node_redirect_output:
X  		tflag |= (RED_FILE|RED_WRITE);
X  		break;
X+ #ifndef MSDOS
X  	case Node_redirect_pipe:
X  		tflag = (RED_PIPE|RED_WRITE);
X  		break;
X***************
X*** 862,867 ****
X--- 861,874 ----
X  	case Node_redirect_pipein:
X  		tflag = (RED_PIPE|RED_READ);
X  		break;
X+ #else
X+ 	case Node_redirect_pipe:
X+ 	case Node_redirect_pipein:
X+ 		fprintf (stderr, "%s: cannot use pipe in PC version.\n",
X+ 			myname);
X+ 		exit(1);
X+ 		break;
X+ #endif
X  	case Node_redirect_input:
X  		tflag = (RED_FILE|RED_READ);
X  		break;
X***************
X*** 900,905 ****
X--- 907,913 ----
X  		case Node_redirect_append:
X  			fp = rp->fp = fdopen(devopen(str, "a"), "a");
X  			break;
X+ #ifndef MSDOS
X  		case Node_redirect_pipe:
X  			fp = rp->fp = popen(str, "w");
X  			break;
X***************
X*** 908,913 ****
X--- 916,922 ----
X  			/* this should bypass popen() */
X  			rp->iop = iop_alloc(fileno(popen(str, "r")));
X  			break;
X+ #endif
X  		case Node_redirect_input:
X  			direction = "from";
X  			rp->iop = iop_alloc(devopen(str, "r"));
X***************
X*** 995,1003 ****
X--- 1004,1014 ----
X  {
X  	int status;
X  
X+ #ifndef MSDOS
X  	if (rp->flag == (RED_PIPE|RED_WRITE))
X  		status = pclose(rp->fp);
X  	else
X+ #endif
X  	if (rp->fp)
X  		status = fclose(rp->fp);
X  	else if (rp->iop)
X***************
X*** 1006,1012 ****
X--- 1017,1025 ----
X  	/* SVR4 awk checks and warns about status of close */
X  	if (status)
X  		warning("%s close of \"%s\" failed (%s).",
X+ #ifndef MSDOS
X  			(rp->flag & RED_PIPE) ? "pipe" :
X+ #endif
X  				"file", rp->value,
X  			sys_errlist[errno]);
X  	if (rp->prev)
X***************
X*** 1037,1043 ****
X--- 1050,1058 ----
X  		if ((rp->flag & RED_WRITE) && rp->fp != NULL)
X  			if (fflush(rp->fp)) {
X  				warning( "%s flush of \"%s\" failed (%s).",
X+ #ifndef MSDOS
X  				    (rp->flag  & RED_PIPE) ? "pipe" :
X+ #endif
X  				    "file", rp->value, sys_errlist[errno]);
X  				status++;
X  			}

END_OF_FILE
echo shar: NEWLINE appended to \"'ppatch'\"
if test 6431 -ne `wc -c <'ppatch'`; then
    echo shar: \"'ppatch'\" unpacked with wrong size!
fi
# end of 'ppatch'
fi
if test -f 'popen.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'popen.c'\"
else
echo shar: Extracting \"'popen.c'\" \(2045 characters\)
sed "s/^X//" >'popen.c' <<'END_OF_FILE'
X#include <stdio.h>
X#include "popen.h"
X#include <io.h>
X#include <string.h>
X#include <process.h>
X
Xstatic char template[] = "piXXXXXX";
Xtypedef enum { unopened = 0, reading, writing } pipemode;
Xstatic
Xstruct {
X    char *command;
X    char *name;
X    pipemode pmode;
X} pipes[_NFILE];
X
XFILE *
Xpopen( char *command, char *mode ) {
X    FILE *current;
X    char *name;
X    int cur;
X    pipemode curmode;
X    /*
X    ** decide on mode.
X    */
X    if(strcmp(mode,"r") == 0)
X        curmode = reading;
X    else if(strcmp(mode,"w") == 0)
X        curmode = writing;
X    else
X        return NULL;
X    /*
X    ** get a name to use.
X    */
X    if((name = tempnam(".","pip"))==NULL)
X        return NULL;
X    /*
X    ** If we're reading, just call system to get a file filled with
X    ** output.
X    */
X    if(curmode == reading) {
X        char cmd[256];
X        sprintf(cmd,"%s > %s",command,name);
X        system(cmd);
X        if((current = fopen(name,"r")) == NULL)
X            return NULL;
X    } else {
X        if((current = fopen(name,"w")) == NULL)
X            return NULL;
X    }
X    cur = fileno(current);
X    pipes[cur].name = name;
X    pipes[cur].pmode = curmode;
X    pipes[cur].command = strdup(command);
X    return current;
X}
X
Xint
Xpclose( FILE * current) {
X    int cur = fileno(current),rval;
X    /*
X    ** check for an open file.
X    */
X    if(pipes[cur].pmode == unopened)
X        return -1;
X    if(pipes[cur].pmode == reading) {
X        /*
X        ** input pipes are just files we're done with.
X        */
X        rval = fclose(current);
X        unlink(pipes[cur].name);
X    } else {
X        /*
X        ** output pipes are temporary files we have
X        ** to cram down the throats of programs.
X        */
X        char command[256];
X        fclose(current);
X        sprintf(command,"%s < %s",pipes[cur].command,pipes[cur].name);
X        rval = system(command);
X        unlink(pipes[cur].name);
X    }
X    /*
X    ** clean up current pipe.
X    */
X    pipes[cur].pmode = unopened;
X    free(pipes[cur].name);
X    free(pipes[cur].command);
X    return rval;
X}

END_OF_FILE
echo shar: NEWLINE appended to \"'popen.c'\"
if test 2046 -ne `wc -c <'popen.c'`; then
    echo shar: \"'popen.c'\" unpacked with wrong size!
fi
# end of 'popen.c'
fi
if test -f 'popen.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'popen.h'\"
else
echo shar: Extracting \"'popen.h'\" \(133 characters\)
sed "s/^X//" >'popen.h' <<'END_OF_FILE'
X/*
X** popen.h -- prototypes for pipe functions
X*/
X#if !defined(FILE)
X#include <stdio.h>
X#endif
Xextern FILE *popen( char *, char * );

END_OF_FILE
echo shar: NEWLINE appended to \"'popen.h'\"
if test 134 -ne `wc -c <'popen.h'`; then
    echo shar: \"'popen.h'\" unpacked with wrong size!
fi
# end of 'popen.h'
fi
echo shar: End of shell archive.
exit 0