[comp.sources.misc] v15i053: dmake version 3.6

dvadura@watdragon.waterloo.edu (Dennis Vadura) (10/15/90)

Posting-number: Volume 15, Issue 53
Submitted-by: Dennis Vadura <dvadura@watdragon.waterloo.edu>
Archive-name: dmake-3.6/part01

#!/bin/sh
# shar:	Shell Archiver  (v1.22)
#
# This is part 1 of a multipart archive                                    
# do not concatenate these parts, unpack them in order with /bin/sh        
#
#	Run the following text with /bin/sh to create:
#	  vextern.h
#	  version.h
#	  unix
#	  unix/sysvr3
#	  unix/sysvr3/time.h
#	  unix/sysvr3/stdlib.h
#	  unix/sysvr3/stdarg.h
#	  unix/sysvr3/startup.mk
#	  unix/sysvr3/runargv.c
#	  unix/sysvr3/make.sh
#	  unix/sysvr3/config.mk
#	  unix/sysvr3/config.h
#	  unix/sysvr1
#	  unix/sysvr1/vfprintf.c
#	  unix/sysvr1/time.h
#	  unix/sysvr1/stdlib.h
#	  unix/sysvr1/stdarg.h
#	  unix/sysvr1/startup.mk
#	  unix/sysvr1/runargv.c
#	  unix/sysvr1/putenv.c
#	  unix/sysvr1/make.sh
#	  unix/sysvr1/config.mk
#	  unix/sysvr1/config.h
#	  unix/sysintf.h
#	  unix/startup.h
#	  unix/ruletab.c
#	  unix/rmprq.c
#	  unix/explode.c
#	  unix/dirbrk.c
#	  unix/config.mk
#	  unix/bsd43
#	  unix/bsd43/vf
#	  unix/bsd43/vf/vfprintf.c
#	  unix/bsd43/vf/startup.mk
#	  unix/bsd43/vf/memcpy.c
#	  unix/bsd43/vf/make.sh
#	  unix/bsd43/vf/ctype.h
#	  unix/bsd43/vf/config.mk
#	  unix/bsd43/uw
#	  unix/bsd43/uw/startup.mk
#	  unix/bsd43/uw/make.sh
#	  unix/bsd43/uw/config.mk
#	  unix/bsd43/utime.c
#	  unix/bsd43/tempnam.c
#	  unix/bsd43/string.h
#	  unix/bsd43/stdlib.h
#	  unix/bsd43/stdarg.h
#	  unix/bsd43/startup.mk
#	  unix/bsd43/setvbuf.c
#	  unix/bsd43/runargv.c
#	  unix/bsd43/putenv.c
#	  unix/bsd43/make.sh
#	  unix/bsd43/config.mk
#	  unix/bsd43/config.h
#	  unix/arlib.c
#	  unix/386ix
#	  unix/386ix/time.h
#	  unix/386ix/stdlib.h
#	  unix/386ix/stdarg.h
#	  unix/386ix/startup.mk
#	  unix/386ix/runargv.c
#	  unix/386ix/make.sh
#	  unix/386ix/config.mk
#	  unix/386ix/config.h
#	  unix/386ix/ar.h
#	  sysintf.c
#	  struct.h
#	  string.c
#	  stat.c
#	  rulparse.c
#	  readme
#	  readme/release
#	  readme/os2
#	  readme/msdos
#	  readme/cover
#	  quit.c
#	  percent.c
#	  path.c
#	  patchlvl.h
#	  parse.c
#	  msdos
#	  msdos/tccdos
#	  msdos/tccdos/utime.c
#	  msdos/tccdos/tempnam.c
#	  msdos/tccdos/startup.mk
#	  msdos/tccdos/objswp.rsp
#	  msdos/tccdos/obj.rsp
#	  msdos/tccdos/mkswp.bat
#	  msdos/tccdos/mk.bat
#	  msdos/tccdos/libswp.rsp
#	  msdos/tccdos/lib.rsp
#	  msdos/tccdos/config.mk
#	  msdos/tccdos/config.h
#	  msdos/sysintf.h
#	  msdos/switchar.c
#	  msdos/stdarg.h
#	  msdos/startup.h
#	  msdos/spawn.c
#	  msdos/runargv.c
#	  msdos/ruletab.c
#	  msdos/rmprq.c
#	  msdos/mscdos
#	  msdos/mscdos/tempnam.c
#	  msdos/mscdos/startup.mk
#	  msdos/mscdos/objswp.rsp
#	  msdos/mscdos/obj60swp.rsp
#	  msdos/mscdos/obj60.rsp
#	  msdos/mscdos/obj.rsp
#	  msdos/mscdos/mkswp.bat
#	  msdos/mscdos/mk60swp.bat
#	  msdos/mscdos/mk60.bat
#	  msdos/mscdos/mk.bat
#	  msdos/mscdos/libswp.rsp
#	  msdos/mscdos/lib60swp.rsp
#	  msdos/mscdos/lib60.rsp
#	  msdos/mscdos/lib.rsp
#	  msdos/mscdos/config.mk
#	  msdos/mscdos/config.h
#	  msdos/find.c
#	  msdos/exec.h
#	  msdos/exec.asm
#	  msdos/dirlib.h
#	  msdos/dirbrk.c
#	  msdos/config.mk
#	  msdos/arlib.c
#	  msdos/_chdir.c
#	  man
#	  man/dmake.tf
#	  man/dmake.p
#	  man/dmake.nc
#	  makefile
#	  makefile.mk
#	  make.c
#	  make.bat
#	  macparse.c
#	  infer.c
#	  imacs.c
#	  hash.c
#	  getinp.c
#	  function.c
#	  extern.h
#	  expand.c
#	  dump.c
#	  dmake.h
#	  dmake.c
#	  dag.c
#	  common
#	  common/stdmacs.h
#	  common/print.mk
#	  common/malloc.c
#	  common/itypes.h
#	  common/dbug.h
#	  common/dbug.c
#	  common/db.h
#	  common/alloc.h
#	  basename.c
#	  _updctl
#	  _install
#	  LICENSE
#
if test -r s2_seq_.tmp
then echo "Must unpack archives in sequence!"
     next=`cat s2_seq_.tmp`; echo "Please unpack part $next next"
     exit 1; fi
echo "x - extracting vextern.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > vextern.h &&
X/* RCS      -- $Header: /u2/dvadura/src/generic/dmake/src/RCS/vextern.h,v 1.1 90/10/06 12:04:31 dvadura Exp $
X-- SYNOPSIS -- global variable declarations.
X-- 
X-- DESCRIPTION
X-- 	Leave _DEFINE_GLOBALS_ undefined and the following declarations
X--	will be defined as global variables, otherwise you get the
X--	external declarations to the same global variables.
X--
X-- AUTHOR
X--      Dennis Vadura, dvadura@watdragon.uwaterloo.ca
X--      CS DEPT, University of Waterloo, Waterloo, Ont., Canada
X--
X-- COPYRIGHT
X--      Copyright (c) 1990 by Dennis Vadura.  All rights reserved.
X-- 
X--      This program is free software; you can redistribute it and/or
X--      modify it under the terms of the GNU General Public License
X--      (version 1), as published by the Free Software Foundation, and
X--      found in the file 'LICENSE' included with this distribution.
X-- 
X--      This program is distributed in the hope that it will be useful,
X--      but WITHOUT ANY WARRANTY; without even the implied warrant of
X--      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
X--      GNU General Public License for more details.
X-- 
X--      You should have received a copy of the GNU General Public License
X--      along with this program;  if not, write to the Free Software
X--      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X--
X-- LOG
X--     $Log:	vextern.h,v $
X * Revision 1.1  90/10/06  12:04:31  dvadura
X * dmake Release, Version 3.6
X * 
X*/
X#include <stdio.h>
X#include "stdmacs.h"
X#include "struct.h"
X#include "dmake.h"
X
X/* These two are defined in dir/ruletab.c and dir/dirbrk.c, and are always
X * imported as externals by the other code.  Their defining modules do not
X * #include this file. */
Xextern	char*	DirBrkStr;	/* pointer to value of macro DIRBRKSTR    */
Xextern	char**	Rule_tab;	/* Builtin rules */
X
X#ifndef _DEFINE_GLOBALS_
X#define EXTERN	extern
X#else
X#define EXTERN
X#endif
X
XEXTERN	int	Line_number;	/* Current line number in make file parse */
XEXTERN	t_attr	Glob_attr;	/* Global attrs to control global ops     */
XEXTERN	char*	Prep;		/* Value of macro PREP			  */
XEXTERN	char*	Makedir;	/* pointer to macro value for MAKEDIR     */
XEXTERN	CELL 	Start_dir;	/* cell for   macro value for .SETDIR	  */
XEXTERN	char*	Shell;		/* pointer to macro value for SHELL       */
XEXTERN	char*	Shell_flags;	/* pointer to macro value for SHELLFLAGS  */
XEXTERN	char*	GShell;		/* pointer to macro value for GROUPSHELL  */
XEXTERN	char*	GShell_flags;	/* pointer to macro value for GROUPFLAGS  */
XEXTERN	char*	Shell_metas;	/* pointer to macro value for SHELLMETAS  */
XEXTERN	char*	Grp_suff;	/* pointer to macro value for GROUPSUFFIX */
XEXTERN  char*   DirSepStr;	/* pointer to macro value for DIRSEPSTR   */
XEXTERN	char*	Pname;		/* dmake process invoke name              */
XEXTERN	char*	Pwd;		/* current working dir, value of PWD	  */
XEXTERN	char*	Augmake;	/* -A */
XEXTERN	int	Target;		/* TRUE if target found in makefile       */
XEXTERN	int	If_expand;	/* TRUE if calling Expand from getinp.c   */
XEXTERN  int	If_multi;	/* M_MULTI for expand of single MULTI macs*/
XEXTERN	int	Readenv;	/* TRUE if defining macro from environment*/
XEXTERN	int	Makemkf;	/* TRUE if making makefile(s)		  */
XEXTERN	int	Nest_level;	/* Nesting level for .IF .ELSE .END ...   */
XEXTERN	int	Def_targets;	/* TRUE if defining targets		  */
X
XEXTERN	LINKPTR Fringe_hd;	/* Pointer to head of the fringe list	  */
XEXTERN	LINKPTR Fringe_tl;	/* Pointer to tail of the fringe list	  */
X
XEXTERN  CELLPTR Recipe_cell; 	/* Current CELL during expansion of recipe*/
XEXTERN  HOWPTR  Recipe_how; 	/* Current HOW during expansion of recipe */
XEXTERN  HOWPTR  Current_target; /* HOW cell of current target being made  */
XEXTERN  HOW     Root_how;	/* HOW CELL for root $(mktmp ..) fns	  */
XEXTERN  int	Wait_for_completion;
XEXTERN  int	Doing_bang;
XEXTERN  int	Packed_shell;	/* TRUE if packed args to use a shell	  */
XEXTERN  int	Swap_on_exec;	/* TRUE if going to swap on exec call     */
X
X/* Command line option flags are defined here.  They correspond one-for one
X * with the flags defined in dmake.c */
X 
XEXTERN	int	Continue;	/* -k */
XEXTERN	int	Get_env;	/* -e or -E */
XEXTERN	int	Force;		/* -u */
XEXTERN	int	Listing;	/* -p */
XEXTERN	int	Rules;		/* -r */
XEXTERN	int	Trace;		/* -n */
XEXTERN	int	Touch;		/* -t */
XEXTERN	int	Check;		/* -q */
XEXTERN	int	Verbose;	/* -v */
XEXTERN	int	Microsoft;	/* -M */
XEXTERN	int	Transitive;	/* -T */
X
XEXTERN	HASHPTR	Macs[HASH_TABLE_SIZE];	/* hash table for macro defs    */
XEXTERN	HASHPTR	Defs[HASH_TABLE_SIZE];	/* hash table for other defs    */
X
XEXTERN	char	*Buffer;		/* a general purpose buffer     */
XEXTERN  int	Buffer_size;
XEXTERN  int	Max_proclmt;		/* limit of max # of conc procs */
XEXTERN	int	Max_proc;		/* max # of conc procs		*/
SHAR_EOF
chmod 0440 vextern.h || echo "restore of vextern.h fails"
echo "x - extracting version.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > version.h &&
X/* dmake version number.  */
X
X#define VERSION "3.60"
SHAR_EOF
chmod 0440 version.h || echo "restore of version.h fails"
echo mkdir - unix
mkdir unix
echo mkdir - unix/sysvr3
mkdir unix/sysvr3
echo "x - extracting unix/sysvr3/time.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > unix/sysvr3/time.h &&
X/*
X** Berkeley get this wrong!
X*/
X#ifndef	TIME_h
X#define	TIME_h
X
Xtypedef	long	time_t;	/* this is the thing we use */
X
X#endif	TIME_h
X
SHAR_EOF
chmod 0440 unix/sysvr3/time.h || echo "restore of unix/sysvr3/time.h fails"
echo "x - extracting unix/sysvr3/stdlib.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > unix/sysvr3/stdlib.h &&
X#ifndef _STDLIB_INCLUDED_
X#define _STDLIB_INCLUDED_
X
Xextern /*GOTO*/ _exit();
Xextern /*GOTO*/ exit();
Xextern /*GOTO*/ abort();
Xextern int system();
Xextern char *getenv();
Xextern char *calloc();
Xextern char *malloc();
Xextern char *realloc();
Xextern free();
Xextern int errno;
X
X#ifndef EIO
X#	include <errno.h>
X#endif
X
X#endif /* _STDLIB_INCLUDED_ */
SHAR_EOF
chmod 0440 unix/sysvr3/stdlib.h || echo "restore of unix/sysvr3/stdlib.h fails"
echo "x - extracting unix/sysvr3/stdarg.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > unix/sysvr3/stdarg.h &&
X/*
X * stdarg.h
X *
X * defines ANSI style macros for accessing arguments of a function which takes
X * a variable number of arguments
X *
X */
X
X#if !defined(__STDARG)
X#define __STDARG
X
Xtypedef char *va_list;
X
X#define va_dcl int va_alist
X#define va_start(ap,v)  ap = (va_list)&va_alist
X#define va_arg(ap,t)    ((t*)(ap += sizeof(t)))[-1]
X#define va_end(ap)      ap = NULL
X#endif
SHAR_EOF
chmod 0440 unix/sysvr3/stdarg.h || echo "restore of unix/sysvr3/stdarg.h fails"
echo "x - extracting unix/sysvr3/startup.mk (Text)"
sed 's/^X//' << 'SHAR_EOF' > unix/sysvr3/startup.mk &&
X# Generic UNIX DMAKE startup file.  Customize to suit your needs.
X# Should work for both SYSV, and BSD 4.3
X# See the documentation for a description of internally defined macros.
X#
X# Disable warnings for macros redefined here that were given
X# on the command line.
X__.SILENT := $(.SILENT)
X.SILENT   := yes
X
X# Configuration parameters for DMAKE startup.mk file
X# Set these to NON-NULL if you wish to turn the parameter on.
X_HAVE_RCS	:= yes		# yes => RCS  is installed.
X_HAVE_SCCS	:= yes		# yes => SCCS is installed.
X
X# Applicable suffix definitions
XA := .a		# Libraries
XE :=		# Executables
XF := .f		# Fortran
XO := .o		# Objects
XP := .p		# Pascal
XS := .s		# Assembler sources
XV := ,v		# RCS suffix
X
X# Recipe execution configurations
XSHELL		:= /bin/sh
XSHELLFLAGS	:= -ce
XGROUPSHELL	:= $(SHELL)
XGROUPFLAGS	:= 
XSHELLMETAS	:= |();&<>?*][$$:\\#`'"
XGROUPSUFFIX	:=
XDIVFILE		 = $(TMPFILE)
X
X# Standard C-language command names and flags
X   CPP	   := /lib/cpp		# C-preprocessor
X   CC      := cc		# C-compiler and flags
X   CFLAGS  +=
X
X   AS      := as		# Assembler and flags
X   ASFLAGS += 
X
X   LD       = $(CC)		# Loader and flags
X   LDFLAGS +=
X   LDLIBS   =
X
X# Definition of $(MAKE) macro for recursive makes.
X   MAKE = $(MAKECMD) $(MFLAGS)
X
X# Definition of Print command for this system.
X   PRINT = lpr
X
X# Language and Parser generation Tools and their flags
X   YACC	  := yacc		# standard yacc
X   YFLAGS +=
X   YTAB	  := y.tab		# yacc output files name stem.
X
X   LEX	  := lex		# standard lex
X   LFLAGS +=
X   LEXYY  := lex.yy		# lex output file
X
X# Other Compilers, Tools and their flags
X   PC	:= pc			# pascal compiler
X   RC	:= f77			# ratfor compiler
X   FC	:= f77			# fortran compiler
X
X   CO	   := co		# check out for RCS
X   COFLAGS += -q
X
X   AR     := ar			# archiver
X   ARFLAGS+= ruv
X
X   RM	   := /bin/rm		# remove a file command
X   RMFLAGS +=
X
X# Implicit generation rules for making inferences.
X# We don't provide .yr or .ye rules here.  They're obsolete.
X# Rules for making *$O
X   %$O : %.c ; $(CC) $(CFLAGS) -c $<
X   %$O : %$P ; $(PC) $(PFLAGS) -c $<
X   %$O : %$S ; $(AS) $(ASFLAGS) $<
X   %$O : %.cl ; class -c $<
X   %$O : %.e %.r %.F %$F
X	$(FC) $(RFLAGS) $(EFLAGS) $(FFLAGS) -c $<
X
X# Executables
X   %$E : %$O ; $(LD) $(LDFLAGS) -o $@ $< $(LDLIBES)
X
X# lex and yacc rules
X   %.c : %.y ; $(YACC)  $(YFLAGS) $<; mv $(YTAB).c $@
X   %.c : %.l ; $(LEX)   $(LFLAGS) $<; mv $(LEXYY).c $@
X
X# This rule tells how to make *.out from it's immediate list of prerequisites
X# UNIX only.
X   %.out :; $(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS)
X
X# RCS support
X.IF $(_HAVE_RCS)
X   % : %$V $$(@:d)RCS/$$(@:f)$V;- $(CO) $(COFLAGS) $@
X   .NOINFER : %$V $$(@:d)RCS/$$(@:f)$V
X.END
X
X# SCCS support
X.IF $(_HAVE_SCCS)
X   % : s.% ; get $@
X   .NOINFER : s.%
X.END
X
X# Recipe to make archive files.
X%$A :
X[
X   $(AR) $(ARFLAGS) $@ $?
X   $(RM) $(RMFLAGS) $?
X   ranlib $@
X]
X
X# DMAKE uses this recipe to remove intermediate targets
X.REMOVE :; $(RM) -f $<
X
X# AUGMAKE extensions for SYSV compatibility
X@B = $(@:b)
X@D = $(@:d)
X@F = $(@:f)
X*B = $(*:b)
X*D = $(*:d)
X*F = $(*:f)
X<B = $(<:b)
X<D = $(<:d)
X<F = $(<:f)
X?B = $(?:b)
X?F = $(?:f)
X?D = $(?:d)
X
X# Turn warnings back to previous setting.
X.SILENT := $(__.SILENT)
X
X# Local startup file if any
X.INCLUDE .IGNORE: "_startup.mk"
SHAR_EOF
chmod 0640 unix/sysvr3/startup.mk || echo "restore of unix/sysvr3/startup.mk fails"
echo "x - extracting unix/sysvr3/runargv.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > unix/sysvr3/runargv.c &&
X/* RCS      -- $Header: /u2/dvadura/src/generic/dmake/src/unix/sysvr3/RCS/runargv.c,v 1.1 90/10/06 12:06:42 dvadura Exp $
X-- SYNOPSIS -- invoke a sub process.
X-- 
X-- DESCRIPTION
X-- 	Use the standard methods of executing a sub process.
X--
X-- AUTHOR
X--      Dennis Vadura, dvadura@watdragon.uwaterloo.ca
X--      CS DEPT, University of Waterloo, Waterloo, Ont., Canada
X--
X-- COPYRIGHT
X--      Copyright (c) 1990 by Dennis Vadura.  All rights reserved.
X-- 
X--      This program is free software; you can redistribute it and/or
X--      modify it under the terms of the GNU General Public License
X--      (version 1), as published by the Free Software Foundation, and
X--      found in the file 'LICENSE' included with this distribution.
X-- 
X--      This program is distributed in the hope that it will be useful,
X--      but WITHOUT ANY WARRANTY; without even the implied warrant of
X--      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
X--      GNU General Public License for more details.
X-- 
X--      You should have received a copy of the GNU General Public License
X--      along with this program;  if not, write to the Free Software
X--      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X--
X-- LOG
X--     $Log:	runargv.c,v $
X * Revision 1.1  90/10/06  12:06:42  dvadura
X * dmake Release, Version 3.6
X * 
X*/
X
X#include <signal.h>
X#include "extern.h"
X#include "sysintf.h"
X#include "alloc.h"
X
Xtypedef struct prp {
X   char *prp_cmd;
X   int   prp_group;
X   int   prp_ignore;
X   int   prp_last;
X   int	 prp_shell;
X   struct prp *prp_next;
X   char  *prp_dir;
X} RCP, *RCPPTR;
X
Xtypedef struct pr {
X   int		pr_valid;
X   int		pr_pid;
X   CELLPTR	pr_target;
X   HOWPTR	pr_how;
X   int		pr_ignore;
X   int		pr_last;
X   RCPPTR  	pr_recipe;
X   RCPPTR  	pr_recipe_end;
X} PR;
X
Xstatic PR  *_procs    = NIL(PR);
Xstatic int  _proc_cnt = 0;
Xstatic int  _abort_flg= FALSE;
Xstatic int  _use_i    = -1;
Xstatic int  _do_upd   = 0;
X
Xstatic  void	_add_child ANSI((int, CELLPTR, HOWPTR, int, int));
Xstatic  void	_attach_cmd ANSI((char *, int, int, CELLPTR, HOWPTR, int, int));
Xstatic  void    _finished_child ANSI((int, int));
Xstatic  int     _running ANSI((CELLPTR, HOWPTR));
X
Xint
Xrunargv(target, how, ignore, group, last, shell, cmd)
XCELLPTR target;
XHOWPTR  how;
Xint     ignore;
Xint	group;
Xint	last;
Xint     shell;
Xchar	*cmd;
X{
X   extern  int  errno;
X   extern  char *sys_errlist[];
X   int          pid;
X   char         **argv;
X
X   if( _running(target, how) /*&& Max_proc != 1*/ ) {
X      /* The command will be executed when the previous recipe
X       * line completes. */
X      _attach_cmd( cmd, group, ignore, target, how, last, shell );
X      return(1);
X   }
X
X   while( _proc_cnt == Max_proc )
X      if( Wait_for_child(FALSE, -1) == -1 )  Fatal( "Lost a child" );
X
X   argv = Pack_argv( group, shell, cmd );
X
X   switch( pid=fork() ){
X      int   wid;
X      int   status;
X
X   case -1: /* fork failed */
X      Error("%s: %s", argv[0], sys_errlist[errno]);
X      Handle_result(-1, ignore, _abort_flg, target);
X      return(-1);
X
X   case 0:  /* child */
X      execvp(argv[0], argv);
X      Continue = TRUE;   /* survive error message */
X      Error("%s: %s", argv[0], sys_errlist[errno]);
X      kill(getpid(), SIGTERM);
X      /*NOTREACHED*/
X
X   default: /* parent */
X      _add_child(pid, target, how, ignore, last);
X   }
X
X   return(1);
X}
X
X
Xint
XWait_for_child( abort_flg, pid )
Xint abort_flg;
Xint pid;
X{
X   int wid;
X   int status;
X   int waitchild;
X
X   waitchild = (pid == -1)? FALSE : Wait_for_completion;
X
X   do {
X      if( (wid = wait(&status)) == -1 ) return(-1);
X
X      _abort_flg = abort_flg;
X      _finished_child(wid, status);
X      _abort_flg = FALSE;
X   }
X   while( waitchild && pid != wid );
X
X   return(0);
X}
X
X
Xvoid
XClean_up_processes()
X{
X   register int i;
X
X   if( _procs != NIL(PR) ) {
X      for( i=0; i<Max_proc; i++ )
X	 if( _procs[i].pr_valid )
X	    kill(_procs[i].pr_pid, SIGTERM);
X
X      while( Wait_for_child(TRUE, -1) != -1 );
X   }
X}
X
X
Xstatic void
X_add_child( pid, target, how, ignore, last )
Xint	pid;
XCELLPTR target;
XHOWPTR  how;
Xint	ignore;
Xint     last;
X{
X   register int i;
X   register PR *pp;
X
X   if( _procs == NIL(PR) ) {
X      TALLOC( _procs, Max_proc, PR );
X   }
X
X   if( (i = _use_i) == -1 )
X      for( i=0; i<Max_proc; i++ )
X	 if( !_procs[i].pr_valid )
X	    break;
X
X   pp = _procs+i;
X
X   pp->pr_valid  = 1;
X   pp->pr_pid    = pid;
X   pp->pr_target = target;
X   pp->pr_how    = how;
X   pp->pr_ignore = ignore;
X   pp->pr_last   = last;
X
X   Current_target = NIL(HOW);
X
X   _proc_cnt++;
X
X   if( Wait_for_completion ) Wait_for_child( FALSE, pid );
X}
X
X
Xstatic void
X_finished_child(pid, status)
Xint	pid;
Xint	status;
X{
X   register int i;
X   register PR *pp;
X
X   for( i=0; i<Max_proc; i++ )
X      if( _procs[i].pr_valid && _procs[i].pr_pid == pid )
X	 break;
X
X   _procs[i].pr_valid = 0;
X   _proc_cnt--;
X
X   if( _procs[i].pr_recipe != NIL(RCP) && !_abort_flg ) {
X      RCPPTR rp = _procs[i].pr_recipe;
X      char   *dir;
X
X      Current_target = _procs[i].pr_how;
X      Handle_result( status, _procs[i].pr_ignore, FALSE, _procs[i].pr_target );
X      Current_target = NIL(HOW);
X
X      _procs[i].pr_recipe = rp->prp_next;
X
X      _use_i = i;
X      dir = _strdup(Get_current_dir());
X      Set_dir( rp->prp_dir );
X      runargv( _procs[i].pr_target, _procs[i].pr_how, rp->prp_ignore,
X      	       rp->prp_group, rp->prp_last, rp->prp_shell, rp->prp_cmd );
X      Set_dir(dir);
X      FREE(dir);
X      FREE(rp->prp_dir);
X      _use_i = -1;
X
X      FREE( rp->prp_cmd );
X      FREE( rp );
X
X      if( _proc_cnt == Max_proc ) Wait_for_child( FALSE, -1 );
X   }
X   else {
X      Unlink_temp_files( _procs[i].pr_how );
X      Handle_result(status,_procs[i].pr_ignore,_abort_flg,_procs[i].pr_target);
X
X      if( _procs[i].pr_last && !Doing_bang )
X	 Update_time_stamp( _procs[i].pr_target, _procs[i].pr_how );
X   }
X}
X
X
Xstatic int
X_running( cp, how )
XCELLPTR cp;
XHOWPTR  how;
X{
X   register int i;
X
X   if( !_procs ) return(FALSE);
X
X   for( i=0; i<Max_proc; i++ )
X      if( _procs[i].pr_valid &&
X	  _procs[i].pr_how == how &&
X	  _procs[i].pr_target == cp  )
X	 break;
X	 
X   return( i != Max_proc );
X}
X
X
Xstatic void
X_attach_cmd( cmd, group, ignore, cp, how, last, shell )
Xchar    *cmd;
Xint	group;
Xint     ignore;
XCELLPTR cp;
XHOWPTR  how;
Xint     last;
Xint     shell;
X{
X   register int i;
X   RCPPTR rp;
X
X   for( i=0; i<Max_proc; i++ )
X      if( _procs[i].pr_valid &&
X	  _procs[i].pr_how == how &&
X	  _procs[i].pr_target == cp  )
X	 break;
X
X   TALLOC( rp, 1, RCP );
X   rp->prp_cmd   = _strdup(cmd);
X   rp->prp_group = group;
X   rp->prp_ignore= ignore;
X   rp->prp_last  = last;
X   rp->prp_shell = shell;
X   rp->prp_dir   = _strdup(Get_current_dir());
X
X   if( _procs[i].pr_recipe == NIL(RCP) )
X      _procs[i].pr_recipe = _procs[i].pr_recipe_end = rp;
X   else {
X      _procs[i].pr_recipe_end->prp_next = rp;
X      _procs[i].pr_recipe_end = rp;
X   }
X}
SHAR_EOF
chmod 0440 unix/sysvr3/runargv.c || echo "restore of unix/sysvr3/runargv.c fails"
echo "x - extracting unix/sysvr3/make.sh (Text)"
sed 's/^X//' << 'SHAR_EOF' > unix/sysvr3/make.sh &&
Xmkdir objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/sysvr3 -O infer.c
Xmv infer.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/sysvr3 -O make.c
Xmv make.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/sysvr3 -O stat.c
Xmv stat.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/sysvr3 -O expand.c
Xmv expand.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/sysvr3 -O string.c
Xmv string.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/sysvr3 -O hash.c
Xmv hash.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/sysvr3 -O dag.c
Xmv dag.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/sysvr3 -O dmake.c
Xmv dmake.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/sysvr3 -O path.c
Xmv path.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/sysvr3 -O imacs.c
Xmv imacs.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/sysvr3 -O sysintf.c
Xmv sysintf.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/sysvr3 -O parse.c
Xmv parse.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/sysvr3 -O getinp.c
Xmv getinp.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/sysvr3 -O quit.c
Xmv quit.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/sysvr3 -O basename.c
Xmv basename.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/sysvr3 -O dump.c
Xmv dump.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/sysvr3 -O macparse.c
Xmv macparse.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/sysvr3 -O rulparse.c
Xmv rulparse.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/sysvr3 -O percent.c
Xmv percent.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/sysvr3 -O function.c
Xmv function.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/sysvr3 -O unix/arlib.c
Xmv arlib.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/sysvr3 -O unix/dirbrk.c
Xmv dirbrk.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/sysvr3 -O unix/explode.c
Xmv explode.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/sysvr3 -O unix/rmprq.c
Xmv rmprq.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/sysvr3 -O unix/ruletab.c
Xmv ruletab.o objects
Xcc -c -DHELP -I. -Icommon -Iunix -Iunix/sysvr3 -O unix/sysvr3/runargv.c
Xmv runargv.o objects
Xcc  -o dmake  objects/infer.o objects/make.o objects/stat.o objects/expand.o objects/string.o objects/hash.o objects/dag.o objects/dmake.o objects/path.o objects/imacs.o objects/sysintf.o objects/parse.o objects/getinp.o objects/quit.o objects/basename.o objects/dump.o objects/macparse.o objects/rulparse.o objects/percent.o objects/function.o objects/arlib.o objects/dirbrk.o objects/explode.o objects/rmprq.o objects/ruletab.o objects/runargv.o 
SHAR_EOF
chmod 0640 unix/sysvr3/make.sh || echo "restore of unix/sysvr3/make.sh fails"
echo "x - extracting unix/sysvr3/config.mk (Text)"
sed 's/^X//' << 'SHAR_EOF' > unix/sysvr3/config.mk &&
X# This is the SysV R3 UNIX configuration file for DMAKE
X#	It simply modifies the values of SRC, and checks to see if
X#	OSENVIRONMENT is defined.  If so it includes the appropriate
X#	config.mk file.
X#
X# It also sets the values of .SOURCE.c and .SOURCE.h to include the local
X# directory.
X#
Xosrdir := $(OS)$(DIRSEPSTR)$(OSRELEASE)
X
X# The following are required sources
XOSDSRC := runargv.c
XSRC    += $(OSDSRC)
X.SETDIR=$(osrdir) : $(OSDSRC)
X
X.SOURCE.h : $(osrdir)
X
X# Local configuration modifications for CFLAGS, there's local SysV includes
X# too.
XCFLAGS += -I$(osrdir)
X
X# See if we modify anything in the lower levels.
X.IF $(OSENVIRONMENT) != $(NULL)
X   .INCLUDE .IGNORE : $(osrdir)$(DIRSEPSTR)$(OSENVIRONMENT)$(DIRSEPSTR)config.mk
X.END
SHAR_EOF
chmod 0640 unix/sysvr3/config.mk || echo "restore of unix/sysvr3/config.mk fails"
echo "x - extracting unix/sysvr3/config.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > unix/sysvr3/config.h &&
X/* RCS      -- $Header: /u2/dvadura/src/generic/dmake/src/unix/sysvr3/RCS/config.h,v 1.1 90/10/06 12:06:39 dvadura Exp $
X-- SYNOPSIS -- Configurarion include file.
X-- 
X-- DESCRIPTION
X-- 	There is one of these for each specific machine configuration.
X--	It can be used to further tweek the machine specific sources
X--	so that they compile.
X--
X-- AUTHOR
X--      Dennis Vadura, dvadura@watdragon.uwaterloo.ca
X--      CS DEPT, University of Waterloo, Waterloo, Ont., Canada
X--
X-- COPYRIGHT
X--      Copyright (c) 1990 by Dennis Vadura.  All rights reserved.
X-- 
X--      This program is free software; you can redistribute it and/or
X--      modify it under the terms of the GNU General Public License
X--      (version 1), as published by the Free Software Foundation, and
X--      found in the file 'LICENSE' included with this distribution.
X-- 
X--      This program is distributed in the hope that it will be useful,
X--      but WITHOUT ANY WARRANTY; without even the implied warrant of
X--      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
X--      GNU General Public License for more details.
X-- 
X--      You should have received a copy of the GNU General Public License
X--      along with this program;  if not, write to the Free Software
X--      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X--
X-- LOG
X--     $Log:	config.h,v $
X * Revision 1.1  90/10/06  12:06:39  dvadura
X * dmake Release, Version 3.6
X * 
X*/
X
X/* define this for configurations that don't have the coreleft function
X * so that the code compiles.  To my knowledge coreleft exists only on
X * Turbo C, but it is needed here since the function is used in many debug
X * macros. */
X#define coreleft() 0L
X
X/* Define the getcwd function that is used in the code, since BSD does
X * not have getcwd, but call it getwd instead. */
Xextern char *getcwd ANSI((char *, int));
X
X/* Define setvbuf, SysV doesn't have one */
X#define setvbuf(fp, bp, type, len) setbuf( fp, NULL );
X
X/* NCR Tower's don't define size_t */
X#ifdef tower
Xtypedef long size_t;
X#endif
SHAR_EOF
chmod 0440 unix/sysvr3/config.h || echo "restore of unix/sysvr3/config.h fails"
echo mkdir - unix/sysvr1
mkdir unix/sysvr1
echo "x - extracting unix/sysvr1/vfprintf.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > unix/sysvr1/vfprintf.c &&
X/* From:
X * John Limpert            johnl@gronk.UUCP        uunet!n3dmc!gronk!johnl
X */
X
X#include <stdio.h>
X#include <varargs.h>
X
X#ifndef BUFSIZ
X#include <stdio.h>
X#endif
X
X#ifndef va_dcl
X#include <varargs.h>
X#endif
X
Xint
Xvsprintf(str, fmt, ap)
X	char *str, *fmt;
X	va_list ap;
X{
X	FILE f;
X	int len;
X
X	f._flag = _IOWRT+_IOMYBUF;
X	f._ptr = (char *)str;	/* My copy of BSD stdio.h has this as (char *)
X				 * with a comment that it should be
X				 * (unsigned char *).  Since this code is
X				 * intended for use on a vanilla BSD system,
X				 * we'll stick with (char *) for now.
X				 */
X	f._cnt = 32767;
X	len = _doprnt(fmt, ap, &f);
X	*f._ptr = 0;
X	return (len);
X}
X
Xint
Xvfprintf(iop, fmt, ap)
X	FILE *iop;
X	char *fmt;
X	va_list ap;
X{
X	int len;
X
X	len = _doprnt(fmt, ap, iop);
X	return (ferror(iop) ? EOF : len);
X}
X
Xint
Xvprintf(fmt, ap)
X	char *fmt;
X	va_list ap;
X{
X	int len;
X
X	len = _doprnt(fmt, ap, stdout);
X	return (ferror(stdout) ? EOF : len);
X}
SHAR_EOF
chmod 0644 unix/sysvr1/vfprintf.c || echo "restore of unix/sysvr1/vfprintf.c fails"
echo "x - extracting unix/sysvr1/time.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > unix/sysvr1/time.h &&
X/*
X** Berkeley get this wrong!
X*/
X#ifndef	TIME_h
X#define	TIME_h
X
Xtypedef	long	time_t;	/* this is the thing we use */
X
X#endif	TIME_h
X
SHAR_EOF
chmod 0440 unix/sysvr1/time.h || echo "restore of unix/sysvr1/time.h fails"
echo "x - extracting unix/sysvr1/stdlib.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > unix/sysvr1/stdlib.h &&
X#ifndef _STDLIB_INCLUDED_
X#define _STDLIB_INCLUDED_
X
Xextern /*GOTO*/ _exit();
Xextern /*GOTO*/ exit();
Xextern /*GOTO*/ abort();
Xextern int system();
Xextern char *getenv();
Xextern char *calloc();
Xextern char *malloc();
Xextern char *realloc();
Xextern free();
Xextern int errno;
X
X#ifndef EIO
X#	include <errno.h>
X#endif
X
X#endif /* _STDLIB_INCLUDED_ */
SHAR_EOF
chmod 0440 unix/sysvr1/stdlib.h || echo "restore of unix/sysvr1/stdlib.h fails"
echo "x - extracting unix/sysvr1/stdarg.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > unix/sysvr1/stdarg.h &&
X/*
X * stdarg.h
X *
X * defines ANSI style macros for accessing arguments of a function which takes
X * a variable number of arguments
X *
X */
X
X#if !defined(__STDARG)
X#define __STDARG
X
Xtypedef char *va_list;
X
X#define va_dcl int va_alist
X#define va_start(ap,v)  ap = (va_list)&va_alist
X#define va_arg(ap,t)    ((t*)(ap += sizeof(t)))[-1]
X#define va_end(ap)      ap = NULL
X#endif
SHAR_EOF
chmod 0440 unix/sysvr1/stdarg.h || echo "restore of unix/sysvr1/stdarg.h fails"
echo "x - extracting unix/sysvr1/startup.mk (Text)"
sed 's/^X//' << 'SHAR_EOF' > unix/sysvr1/startup.mk &&
X# Generic UNIX DMAKE startup file.  Customize to suit your needs.
X# Should work for both SYSV, and BSD 4.3
X# See the documentation for a description of internally defined macros.
X#
X# Disable warnings for macros redefined here that were given
X# on the command line.
X__.SILENT := $(.SILENT)
X.SILENT   := yes
X
X# Configuration parameters for DMAKE startup.mk file
X# Set these to NON-NULL if you wish to turn the parameter on.
X_HAVE_RCS	:= yes		# yes => RCS  is installed.
X_HAVE_SCCS	:= yes		# yes => SCCS is installed.
X
X# Applicable suffix definitions
XA := .a		# Libraries
XE :=		# Executables
XF := .f		# Fortran
XO := .o		# Objects
XP := .p		# Pascal
XS := .s		# Assembler sources
XV := ,v		# RCS suffix
X
X# Recipe execution configurations
XSHELL		:= /bin/sh
XSHELLFLAGS	:= -ce
XGROUPSHELL	:= $(SHELL)
XGROUPFLAGS	:= 
XSHELLMETAS	:= |();&<>?*][$$:\\#`'"
XGROUPSUFFIX	:=
XDIVFILE		 = $(TMPFILE)
X
X# Standard C-language command names and flags
X   CPP	   := /lib/cpp		# C-preprocessor
X   CC      := cc		# C-compiler and flags
X   CFLAGS  +=
X
X   AS      := as		# Assembler and flags
X   ASFLAGS += 
X
X   LD       = $(CC)		# Loader and flags
X   LDFLAGS +=
X   LDLIBS   =
X
X# Definition of $(MAKE) macro for recursive makes.
X   MAKE = $(MAKECMD) $(MFLAGS)
X
X# Definition of Print command for this system.
X   PRINT = lpr
X
X# Language and Parser generation Tools and their flags
X   YACC	  := yacc		# standard yacc
X   YFLAGS +=
X   YTAB	  := y.tab		# yacc output files name stem.
X
X   LEX	  := lex		# standard lex
X   LFLAGS +=
X   LEXYY  := lex.yy		# lex output file
X
X# Other Compilers, Tools and their flags
X   PC	:= pc			# pascal compiler
X   RC	:= f77			# ratfor compiler
X   FC	:= f77			# fortran compiler
X
X   CO	   := co		# check out for RCS
X   COFLAGS += -q
X
X   AR     := ar			# archiver
X   ARFLAGS+= ruv
X
X   RM	   := /bin/rm		# remove a file command
X   RMFLAGS +=
X
X# Implicit generation rules for making inferences.
X# We don't provide .yr or .ye rules here.  They're obsolete.
X# Rules for making *$O
X   %$O : %.c ; $(CC) $(CFLAGS) -c $<
X   %$O : %$P ; $(PC) $(PFLAGS) -c $<
X   %$O : %$S ; $(AS) $(ASFLAGS) $<
X   %$O : %.cl ; class -c $<
X   %$O : %.e %.r %.F %$F
X	$(FC) $(RFLAGS) $(EFLAGS) $(FFLAGS) -c $<
X
X# Executables
X   %$E : %$O ; $(LD) $(LDFLAGS) -o $@ $< $(LDLIBES)
X
X# lex and yacc rules
X   %.c : %.y ; $(YACC)  $(YFLAGS) $<; mv $(YTAB).c $@
X   %.c : %.l ; $(LEX)   $(LFLAGS) $<; mv $(LEXYY).c $@
X
X# This rule tells how to make *.out from it's immediate list of prerequisites
X# UNIX only.
X   %.out :; $(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS)
X
X# RCS support
X.IF $(_HAVE_RCS)
X   % : %$V $$(@:d)RCS/$$(@:f)$V;- $(CO) $(COFLAGS) $@
X   .NOINFER : %$V $$(@:d)RCS/$$(@:f)$V
X.END
X
X# SCCS support
X.IF $(_HAVE_SCCS)
X   % : s.% ; get $@
X   .NOINFER : s.%
X.END
X
X# Recipe to make archive files.
X%$A :
X[
X   $(AR) $(ARFLAGS) $@ $?
X   $(RM) $(RMFLAGS) $?
X   ranlib $@
X]
X
X# DMAKE uses this recipe to remove intermediate targets
X.REMOVE :; $(RM) -f $<
X
X# AUGMAKE extensions for SYSV compatibility
X@B = $(@:b)
X@D = $(@:d)
X@F = $(@:f)
X*B = $(*:b)
X*D = $(*:d)
X*F = $(*:f)
X<B = $(<:b)
X<D = $(<:d)
X<F = $(<:f)
X?B = $(?:b)
X?F = $(?:f)
X?D = $(?:d)
X
X# Turn warnings back to previous setting.
X.SILENT := $(__.SILENT)
X
X# Local startup file if any
X.INCLUDE .IGNORE: "_startup.mk"
SHAR_EOF
chmod 0640 unix/sysvr1/startup.mk || echo "restore of unix/sysvr1/startup.mk fails"
echo "x - extracting unix/sysvr1/runargv.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > unix/sysvr1/runargv.c &&
X/* RCS      -- $Header: /u2/dvadura/src/generic/dmake/src/unix/sysvr1/RCS/runargv.c,v 1.1 90/10/06 12:06:32 dvadura Exp $
X-- SYNOPSIS -- invoke a sub process.
X-- 
X-- DESCRIPTION
X-- 	Use the standard methods of executing a sub process.
X--
X-- AUTHOR
X--      Dennis Vadura, dvadura@watdragon.uwaterloo.ca
X--      CS DEPT, University of Waterloo, Waterloo, Ont., Canada
X--
X-- COPYRIGHT
X--      Copyright (c) 1990 by Dennis Vadura.  All rights reserved.
X-- 
X--      This program is free software; you can redistribute it and/or
X--      modify it under the terms of the GNU General Public License
X--      (version 1), as published by the Free Software Foundation, and
X--      found in the file 'LICENSE' included with this distribution.
X-- 
X--      This program is distributed in the hope that it will be useful,
X--      but WITHOUT ANY WARRANTY; without even the implied warrant of
X--      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
X--      GNU General Public License for more details.
X-- 
X--      You should have received a copy of the GNU General Public License
X--      along with this program;  if not, write to the Free Software
X--      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X--
X-- LOG
X--     $Log:	runargv.c,v $
X * Revision 1.1  90/10/06  12:06:32  dvadura
X * dmake Release, Version 3.6
X * 
X*/
X
X#include <signal.h>
X#include "extern.h"
X#include "sysintf.h"
X#include "alloc.h"
X
Xtypedef struct prp {
X   char *prp_cmd;
X   int   prp_group;
X   int   prp_ignore;
X   int   prp_last;
X   int	 prp_shell;
X   struct prp *prp_next;
X   char  *prp_dir;
X} RCP, *RCPPTR;
X
Xtypedef struct pr {
X   int		pr_valid;
X   int		pr_pid;
X   CELLPTR	pr_target;
X   HOWPTR	pr_how;
X   int		pr_ignore;
X   int		pr_last;
X   RCPPTR  	pr_recipe;
X   RCPPTR  	pr_recipe_end;
X} PR;
X
Xstatic PR  *_procs    = NIL(PR);
Xstatic int  _proc_cnt = 0;
Xstatic int  _abort_flg= FALSE;
Xstatic int  _use_i    = -1;
Xstatic int  _do_upd   = 0;
X
Xstatic  void	_add_child ANSI((int, CELLPTR, HOWPTR, int, int));
Xstatic  void	_attach_cmd ANSI((char *, int, int, CELLPTR, HOWPTR, int, int));
Xstatic  void    _finished_child ANSI((int, int));
Xstatic  int     _running ANSI((CELLPTR, HOWPTR));
X
Xint
Xrunargv(target, how, ignore, group, last, shell, cmd)
XCELLPTR target;
XHOWPTR  how;
Xint     ignore;
Xint	group;
Xint	last;
Xint     shell;
Xchar	*cmd;
X{
X   extern  int  errno;
X   extern  char *sys_errlist[];
X   int          pid;
X   char         **argv;
X
X   if( _running(target, how) /*&& Max_proc != 1*/ ) {
X      /* The command will be executed when the previous recipe
X       * line completes. */
X      _attach_cmd( cmd, group, ignore, target, how, last, shell );
X      return(1);
X   }
X
X   while( _proc_cnt == Max_proc )
X      if( Wait_for_child(FALSE, -1) == -1 )  Fatal( "Lost a child" );
X
X   argv = Pack_argv( group, shell, cmd );
X
X   switch( pid=fork() ){
X      int   wid;
X      int   status;
X
X   case -1: /* fork failed */
X      Error("%s: %s", argv[0], sys_errlist[errno]);
X      Handle_result(-1, ignore, _abort_flg, target);
X      return(-1);
X
X   case 0:  /* child */
X      execvp(argv[0], argv);
X      Continue = TRUE;   /* survive error message */
X      Error("%s: %s", argv[0], sys_errlist[errno]);
X      kill(getpid(), SIGTERM);
X      /*NOTREACHED*/
X
X   default: /* parent */
X      _add_child(pid, target, how, ignore, last);
X   }
X
X   return(1);
X}
X
X
Xint
XWait_for_child( abort_flg, pid )
Xint abort_flg;
Xint pid;
X{
X   int wid;
X   int status;
X   int waitchild;
X
X   waitchild = (pid == -1)? FALSE : Wait_for_completion;
X
X   do {
X      if( (wid = wait(&status)) == -1 ) return(-1);
X
X      _abort_flg = abort_flg;
X      _finished_child(wid, status);
X      _abort_flg = FALSE;
X   }
X   while( waitchild && pid != wid );
X
X   return(0);
X}
X
X
Xvoid
XClean_up_processes()
X{
X   register int i;
X
X   if( _procs != NIL(PR) ) {
X      for( i=0; i<Max_proc; i++ )
X	 if( _procs[i].pr_valid )
X	    kill(_procs[i].pr_pid, SIGTERM);
X
X      while( Wait_for_child(TRUE, -1) != -1 );
X   }
X}
X
X
Xstatic void
X_add_child( pid, target, how, ignore, last )
Xint	pid;
XCELLPTR target;
XHOWPTR  how;
Xint	ignore;
Xint     last;
X{
X   register int i;
X   register PR *pp;
X
X   if( _procs == NIL(PR) ) {
X      TALLOC( _procs, Max_proc, PR );
X   }
X
X   if( (i = _use_i) == -1 )
X      for( i=0; i<Max_proc; i++ )
X	 if( !_procs[i].pr_valid )
X	    break;
X
X   pp = _procs+i;
X
X   pp->pr_valid  = 1;
X   pp->pr_pid    = pid;
X   pp->pr_target = target;
X   pp->pr_how    = how;
X   pp->pr_ignore = ignore;
X   pp->pr_last   = last;
X
X   Current_target = NIL(HOW);
X
X   _proc_cnt++;
X
X   if( Wait_for_completion ) Wait_for_child( FALSE, pid );
X}
X
X
Xstatic void
X_finished_child(pid, status)
Xint	pid;
Xint	status;
X{
X   register int i;
X   register PR *pp;
X
X   for( i=0; i<Max_proc; i++ )
X      if( _procs[i].pr_valid && _procs[i].pr_pid == pid )
X	 break;
X
X   _procs[i].pr_valid = 0;
X   _proc_cnt--;
X
X   if( _procs[i].pr_recipe != NIL(RCP) && !_abort_flg ) {
X      RCPPTR rp = _procs[i].pr_recipe;
X      char   *dir;
X
X      Current_target = _procs[i].pr_how;
X      Handle_result( status, _procs[i].pr_ignore, FALSE, _procs[i].pr_target );
X      Current_target = NIL(HOW);
X
X      _procs[i].pr_recipe = rp->prp_next;
X
X      _use_i = i;
X      dir = _strdup(Get_current_dir());
X      Set_dir( rp->prp_dir );
X      runargv( _procs[i].pr_target, _procs[i].pr_how, rp->prp_ignore,
X      	       rp->prp_group, rp->prp_last, rp->prp_shell, rp->prp_cmd );
X      Set_dir(dir);
X      FREE(dir);
X      FREE(rp->prp_dir);
X      _use_i = -1;
X
X      FREE( rp->prp_cmd );
X      FREE( rp );
X
X      if( _proc_cnt == Max_proc ) Wait_for_child( FALSE, -1 );
X   }
X   else {
X      Unlink_temp_files( _procs[i].pr_how );
X      Handle_result(status,_procs[i].pr_ignore,_abort_flg,_procs[i].pr_target);
X
X      if( _procs[i].pr_last && !Doing_bang )
X	 Update_time_stamp( _procs[i].pr_target, _procs[i].pr_how );
X   }
X}
X
X
Xstatic int
X_running( cp, how )
XCELLPTR cp;
XHOWPTR  how;
X{
X   register int i;
X
X   if( !_procs ) return(FALSE);
SHAR_EOF
echo "End of part 1"
echo "File unix/sysvr1/runargv.c is continued in part 2"
echo "2" > s2_seq_.tmp
exit 0