[comp.sources.unix] v19i038: A software configuration management system, Part25/33

rsalz@uunet.uu.net (Rich Salz) (06/07/89)

Submitted-by: Axel Mahler <unido!coma!axel>
Posting-number: Volume 19, Issue 38
Archive-name: shape/part25



#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 25 (of 33)."
# Contents:  src/shape/produce.c
# Wrapped by rsalz@papaya.bbn.com on Thu Jun  1 19:27:16 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'src/shape/produce.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'src/shape/produce.c'\"
else
echo shar: Extracting \"'src/shape/produce.c'\" \(27571 characters\)
sed "s/^X//" >'src/shape/produce.c' <<'END_OF_FILE'
X/*
X * Copyright (C) 1989, 1990 W. Koch, A. Lampen, A. Mahler, W. Obst,
X *  and U. Pralle
X * 
X * This software is published on an as-is basis. There is ABSOLUTELY NO
X * WARRANTY for any part of this software to work correctly or as described
X * in the manuals. We do not accept any liability for any kind of damage
X * caused by use of this software, such as loss of data, time, money, or 
X * effort.
X * 
X * Permission is granted to use, copy, modify, or distribute any part of
X * this software as long as this is done without asking for charge, and
X * provided that this copyright notice is retained as part of the source
X * files. You may charge a distribution fee for the physical act of
X * transferring a copy, and you may at your option offer warranty
X * protection in exchange for a fee.
X * 
X * Direct questions to: Tech. Univ. Berlin
X * 		     Wilfried Koch
X * 		     Sekr. FR 5-6 
X * 		     Franklinstr. 28/29
X * 		     D-1000 Berlin 10, West Germany
X * 
X * 		     Tel: +49-30-314-22972
X * 		     E-mail: shape@coma.uucp or shape@db0tui62.bitnet
X */
X#ifndef lint
Xstatic char *RCSid = "$Header: produce.c,v 3.4 89/02/21 17:11:28 wolfgang Exp $";
X#endif
X#ifndef lint
Xstatic char *ConfFlg = CFFLGS;	/* should be defined from within Makefile */
X#endif
X/*
X * $Log:	produce.c,v $
X * Revision 3.4  89/02/21  17:11:28  wolfgang
X * bug fixed
X * 
X * Revision 3.3  89/02/20  16:26:17  wolfgang
X * NET-RELEASE
X * 
X * Revision 3.2  89/02/14  21:20:51  wolfgang
X * bug fixed.
X * 
X * Revision 3.1  89/02/08  12:45:15  wolfgang
X * performance improved.
X * 
X * Revision 3.0  89/01/24  11:36:19  wolfgang
X * New System Generation
X * 
X * Revision 2.39  89/01/19  12:37:14  wolfgang
X * .DEFAULT added.
X * 
X * Revision 2.38  89/01/18  13:40:59  wolfgang
X * bug fixed: if -n specified the message 'target is up to date' was printed out
X * 
X * Revision 2.37  89/01/13  12:38:37  wolfgang
X * bug fixed. -k option doesn't work correct.
X * 
X * Revision 2.36  89/01/03  13:12:35  wolfgang
X * changes done for lint
X * 
X * Revision 2.35  88/12/22  13:23:38  wolfgang
X * error_occ added.
X * 
X * Revision 2.34  88/12/22  12:33:40  wolfgang
X * bug fixed. handling of -k option has not been correct.
X * call of cleanup_links added.
X * 
X * Revision 2.33  88/12/21  15:11:21  wolfgang
X * changes done for lint
X * 
X * Revision 2.32  88/12/12  13:15:07  wolfgang
X * bug fixed. single suffix rules didn't work
X * 
X * Revision 2.31  88/11/24  12:08:05  wolfgang
X * Argument for -confid *must* now be a target name.
X * 
X * Revision 2.30  88/11/21  20:54:56  wolfgang
X * changes done for sun
X * 
X * Revision 2.29  88/11/21  15:50:07  wolfgang
X * return code of all malloc's checked
X * 
X * Revision 2.28  88/11/09  16:27:05  wolfgang
X * inheritage changed.
X * 
X * Revision 2.27  88/10/27  16:37:04  wolfgang
X * bugs fixed (new variant handling).
X * 
X * Revision 2.26  88/10/26  13:12:45  wolfgang
X * changes done for new syntax of variant deps.
X * 
X * Revision 2.25  88/10/24  16:20:25  wolfgang
X * calls of reduce_path_and_flags() deleted
X * 
X * Revision 2.24  88/10/21  14:56:42  wolfgang
X * calls of attrvar added.
X * 
X * Revision 2.23  88/10/18  17:40:24  wolfgang
X * changes done for new variant handling
X * 
X * Revision 2.22  88/10/10  16:53:24  wolfgang
X * changes for option -t
X * 
X * Revision 2.21  88/10/03  12:54:19  wolfgang
X * if via the -R option an unknown selection rule name is passed to shape, shape
X * now stops (correctly!!).
X * 
X * Revision 2.20  88/09/26  14:15:40  wolfgang
X * strange bug fixed in reduce_vpath_and_vflags (perhaps a malloc problem).
X * 
X * Revision 2.19  88/09/22  18:57:09  wolfgang
X * bug fixed. activ selection rule is now correct (hopefully).
X * 
X * Revision 2.18  88/09/22  16:13:35  wolfgang
X * bugs fixed.
X * 
X * Revision 2.17  88/09/22  10:04:04  wolfgang
X * bugs fixed. ruleset & reset vflags.
X * 
X * Revision 2.16  88/09/20  10:24:53  wolfgang
X * bug fixed. segmentation violation in set_pathi due to non-initialization 
X * of i.
X * 
X * Revision 2.15  88/09/20  10:03:21  wolfgang
X * set_pathi() added.
X * 
X * Revision 2.14  88/09/19  15:23:32  wolfgang
X * This version is part of a release
X * 
X * Revision 2.13  88/09/19  14:41:42  wolfgang
X * Bugs fixed. Single suffix rules weren't evaluated corectly
X * 
X * Revision 2.12  88/09/15  18:41:40  wolfgang
X * calls of set_path_and_flags deleted.
X * 
X * Revision 2.11  88/09/14  14:00:26  wolfgang
X * bug fixed. variant path & flags have not been reset correctly.
X * 
X * Revision 2.10  88/09/14  12:15:27  wolfgang
X * minor bug fixed.
X * 
X * Revision 2.9  88/09/14  10:52:46  wolfgang
X * undone last changes
X * 
X * Revision 2.8  88/09/13  09:56:29  wolfgang
X * Changes done to allow overloading of imlpicit standard rules.
X * 
X * Revision 2.7  88/09/07  11:25:29  wolfgang
X * This version is part of a release
X * 
X * Revision 2.6  88/08/31  12:04:00  wolfgang
X * Bugs fixed.
X * 
X * Revision 2.5  88/08/25  16:03:37  wolfgang
X * Little but effectful change (the procedure select gets more and more
X * unnecessary).
X * 
X * Revision 2.4  88/08/23  16:39:02  wolfgang
X * Rebuild feature added (to rebuild something from a confid).
X * 
X * Revision 2.3  88/08/22  10:14:15  wolfgang
X * Changed produce(), so that it is no longer necessary to have a descrition
X * file. It's enaugh to have the name of a target to produce on the command
X * line.
X * 
X * Revision 2.2  88/08/19  17:02:31  wolfgang
X * little bug fix.
X * 
X * Revision 2.1  88/08/19  10:17:42  wolfgang
X * This version is part of a release
X * 
X */
X
X/* $? neu machen !!!! ????? */
X
X
X#include "shape.h"
X#define MAXCMDLENGTH 1024
Xextern char *rindex();
X
XBool error_happened = FALSE;
XBool error_occ = FALSE;
X
Xextern int cleanup_links();
Xextern struct linkreg *link_reg;
Xextern int free_linklist();
Xextern void warning();
Xextern int errexit();
Xextern int hashval();
Xextern char *expandmacro();
Xextern char *repl_string();
Xextern char *get_src_name();
Xextern char *build_attrstring();
Xextern Bool compare_attrstring();
Xextern Bool exists_file();
Xextern Bool Sselect();
Xextern Bool evtl_set_busy();
Xextern Bool is_selrule_name();
Xextern Bool is_varname();
Xextern Bool attrvar();
Xextern int save_targets();
Xextern char cfname[];
Xextern struct rules *ruletab[];
Xextern int implicit_suffs[];
Xextern int pathi;
Xextern char *cmdtargets[];
Xextern char *firsttarget;
Xextern char actpath[];
Xextern char cursr[];
Xextern char *curvar[];
Xextern char *longattrs[];
Xextern char *stdselrule;
Xextern struct selection_rules *std_selrule;
Xextern struct selection_rules *currule;
Xextern int variants_active;
X
Xchar rbrule[64];
Xchar rbtarg[64];
Xchar ruleset[32];
Xchar lastcurdep[MAXNAMLEN];
X
Xchar current_dep[MAXNAMLEN];
XBool busy_done = FALSE;
XBool reallydone = FALSE;
Xint depth;
Xchar *default_targets = ".DEFAULT";
X
X
Xchar *expand_command (cmd, cur, rel_dep)
X     char *cmd;
X     struct rules *cur;
X     char *rel_dep;
X{
X  char *curdep;
X  char *comm;
X  int i = 0;
X  int j = 0;
X  int k = 0;
X  char *common_prefix;
X  char *p;
X  char *hhhp, *hhh2p;
X  char hhh[64];
X  char hhh2[64];
X  Bool ttt = FALSE;
X  char path1[MAXNAMLEN];
X  if((comm = malloc(MAXCMDLENGTH * sizeof(char))) == NIL)
X    errexit(10,"malloc");
X  
X  while(cmd[i] != '\0')
X    {
X      if((cmd[i] != '$') && (cmd[i] != '%'))
X	{
X	  comm[j] =  cmd[i];
X	  i++;
X	  j++;
X	}
X      else
X	{
X	  switch (cmd[i+1])
X	    {
X	    case '@':
X	      if (cur->name[0] != '%')
X		{
X		  comm[j] = '\0';
X		  (void) strcat(comm, cur->name);
X		  (void) strcat(comm," ");
X		  j = j + strlen(cur->name) + 1;
X		  i = i + 2;
X		}
X	      else
X		{
X		  comm[j] = '\0';
X		  (void) strcpy(hhh,rel_dep);
X		  hhhp = rindex(hhh,'.');
X		  if (hhhp != NIL)
X		    {
X		      hhhp[0] = '\0';
X		    }
X		  (void) strcpy(hhh2, cur->name);
X		  hhh2p = rindex(hhh2,'.');
X		  (void) strcat(hhh,hhh2p);
X		  (void) strcat(comm, hhh);
X		  (void) strcat(comm, " ");
X		  j = j + strlen(hhh) + 1;
X		  i = i + 2;
X		}
X	      
X	      break;
X	    case '?':
X	      if (cur->deplist[0] != NIL)
X		{
X		  k = 1;
X		  curdep = cur->deplist[0];
X		  ttt = exists_file(cur->name,0);
X		  (void) strcpy(path1,actpath);
X		  /*		  strcpy(actpath,"");  */
X		  while(curdep != NIL)
X		    {
X		      if (Sselect(cur->name, path1, ttt, cur->deplist[0],curdep))
X			/* if (cur->date < curdep->date)  ????? */
X			{
X			  comm[j] = '\0';
X			  (void) strcat(comm, curdep);
X			  (void) strcat(comm," ");
X			  j = j + strlen(curdep) + 1;
X			}
X		      k++;
X		      curdep = cur->deplist[k];
X		    }
X		}
X	      i = i + 2;
X	      break;
X	    case '<':
X	      comm[j] = '\0';
X	      if (strcmp(actpath,"") != 0)
X		{
X		  (void) strcat(comm,actpath);
X		  (void) strcat(comm,"/");
X		  j = j + strlen(actpath) + 1;
X		}
X	      (void) strcat(comm, rel_dep);
X	      (void) strcat(comm, " ");
X	      j = j + strlen(rel_dep) + 1;
X	      i = i + 2;
X	      break;
X	    case '*':
X	    case '.':
X	    case ' ':
X	      if (cur->name[0] != '%')
X		{
X		  if ((common_prefix = malloc((unsigned) (strlen(cur->name) + 1))) == NIL)
X		    errexit(10,"malloc");
X		  (void) strcpy(common_prefix, cur->name);
X		  if ((p = rindex(common_prefix,'.')) != NIL)
X		    {
X		      p[0] = '\0';
X		    }
X		  comm[j] = '\0';
X		  (void) strcat(comm, common_prefix);
X		  j = j + strlen(common_prefix);
X		  if (cmd[i+1] == '*')
X		    i = i + 2;
X		  else
X		    i++;
X		}
X	      else
X		{
X		  comm[j] = '\0';
X		  (void) strcpy(hhh,rel_dep);
X		  hhhp = rindex(hhh,'.');
X		  if(hhhp != NIL)
X		    {
X		      hhhp[1] = '\0';
X		    }
X		  (void) strcat(comm, hhh);
X		  j = j + strlen(hhh);
X		  if (cur->name[1] == '.')
X		    i = i + 2;
X		  else
X		    i = i+1;
X		}
X	      
X	      break;
X	    case '(':
X	      errexit(99,"output tarnslation $(name:str1=str2)");
X	      /* ???? output translation, not yet implemented */
X	      break;
X	    case '$':
X	      comm[j] = '$';
X	      j++;
X	      i = i+2;
X	      break;
X	    default:
X	      if(cmd[i] == '%')
X		/* single suffix rule */
X		{
X		  comm[j] = '\0';
X		  (void) strcpy(hhh,rel_dep);
X		  hhhp = rindex(hhh,'.');
X		  if(hhhp != NIL)
X		    {
X		      hhhp[1] = '\0';
X		    }
X		  (void) strcat(comm, hhh);
X		  j = j + strlen(hhh);
X		  i = i+1;
X		}
X	      else
X		{
X		  comm[j] = cmd[i];
X		  j++;
X		  i++;
X		}
X	      break;
X	    }
X	}
X    }
X  comm[j] = '\0';
X  if (comm[0] == '\0')
X    (void) strcpy(comm,cmd);
X  return(comm);
X}
X
X
Xstruct rules *get_target(targ)
X     char *targ;
X{
X  int hasht;
X  struct rules *current = (struct rules *) NIL;
X  char *p = NIL;
X  char fname[MAXNAMLEN];
X  char fnames[10][MAXNAMLEN];
X  char targrulename[MAXNAMLEN];
X  int i;
X  int j;
X  Bool ttt = FALSE;
X  Bool tttt = TRUE;
X  Bool xxx = TRUE;
X  char path1[MAXNAMLEN];
X  
X  if (targ == NIL)
X    return((struct rules *) NIL);
X  
X  hasht = hashval(targ);
X  
X  if ( ruletab[hasht] != (struct rules *) NIL)
X    {
X      current = ruletab[hasht];
X      while((current != (struct rules *) NIL ) && (strcmp(targ, current->name) != 0))
X	{
X	  current = current->nextrule;
X	}
X    }
X  if (current != (struct rules *) NIL)
X    {
X      if (strcmp(targ, current->name) == 0)
X	return(current);
X    }
X  if ((ruletab[hasht] == (struct rules *) NIL) || ((current == (struct rules *) NIL)) || (strcmp(targ,current->name) != 0))
X    {
X      /* look for std rule */
X
X      if (TRUE)
X	{
X	  p = rindex(fname,'.');
X	  ttt = exists_file(targ,0);
X	  (void) strcpy(path1, actpath);
X	  (void) strcpy(actpath,"");
X	  for(i = 0; implicit_suffs[i] != -1; i++)
X	    {
X	      (void) strcpy(fname,targ);
X	      p = rindex(fname,'.');
X  
X	      tttt = TRUE;
X	      /* build source name */
X	      if (p != NIL)
X		*p = '\0';   /* p = suffix of target */
X	      if (p != NIL)
X		(void) strcpy(targrulename,"%.");
X	      else
X		(void) strcpy(targrulename,"%");
X	      if (p != NIL)
X		(void) strcat(targrulename,p + 1);
X	      if (strcmp(targrulename, stdruletab[implicit_suffs[i]]->name) == 0)
X		{
X		  /* several dependents may be necessary */
X
X		  for (j = 0; j < 10; j++)
X		    {
X		      fnames[j][0] = '\0';
X		    }
X		  
X		  for (j = 0; stdruletab[implicit_suffs[i]]->deplist[j] != NIL; j++)
X		    {
X		      (void) strcat(fname,stdruletab[implicit_suffs[i]]->deplist[j]+1);
X		      tttt = tttt && exists_file(fname,0);
X		      if (tttt)
X			(void) strcpy(fnames[j],fname);
X		      if (p != NIL)
X			*p = '\0';
X		      else
X			(void) strcpy(fname,targ);
X		    }
X		  if(tttt)
X		    {
X		      
X		      if (TRUE)
X			{
X			  j = 0;
X			  xxx = TRUE;
X			  while((fnames[j][0] != '\0') && (xxx))
X			    {
X			      xxx = xxx && evtl_set_busy(fnames[j], FALSE);
X			      if (!xxx)
X				break;
X			      j++;
X			    }
X			  if (xxx)
X			    {
X			      for (j = 0; fnames[j][0] != '\0'; j++)
X				(void) evtl_set_busy(fnames[j], TRUE);
X			      (void) strcpy(current_dep,targ);
X			      return(stdruletab[implicit_suffs[i]]);
X			    }
X			}
X		      
X		      if(!ttt)
X			{
X			  /* to get the attrs .... */
X			  (void) Sselect(targ, path1, ttt, NIL, fnames[0]);/* ???? */
X			  
X			  (void) strcpy(current_dep,targ);
X			  return(stdruletab[implicit_suffs[i]]);
X			}
X		      
X		      if(Sselect(targ, path1, ttt, NIL, fnames[0])) /* ??? */
X			{
X			  (void) strcpy(current_dep,targ);
X			  return(stdruletab[implicit_suffs[i]]);
X			}
X		      else
X			return (struct rules *) NIL;
X		    }
X		}
X	    }
X	  if(implicit_suffs[i] == -1)
X	    return (struct rules *) NIL;
X	}
X    }
X  /*NOTREACHED*/
X  return (struct rules *) NIL;
X}
X
X
Xproduce()
X{
X  int k = 0;
X  char *comm;
X
X  if(confid)
X    {
X      if((get_target(cfname) == (struct rules *) NIL))
X	errexit(35,cfname);
X    }
X      
X  set_pathi();
X
X  (void) strcpy(cursr,"-STD-");
X
X  if (cmdtargets[0] == NIL) /* no targets on commandline */
X    {
X      if((get_target(".DEFAULT") != (struct rules *) NIL))
X	comm = default_targets;
X      else
X	comm = firsttarget;
X    }
X  else
X    comm = cmdtargets[k++];
X
X  if((nostdfile == TRUE) && (fileflg == FALSE) && (cmdtargets[0] == NIL))
X    errexit(11,NIL);
X  
X  if (!rebuildflg)
X    {
X      if (ruleflg)
X	{
X	  if (is_selrule_name(ruleset))
X	    (void) strcpy(cursr,ruleset);
X	  else
X	    errexit(32,ruleset);
X	}
X      else
X	(void) strcpy(cursr,"-STD-");
X    }
X  else
X    (void) strcpy(cursr,rbrule);
X  
X  if (!rebuildflg)
X    {
X      while (comm != NIL)
X	{
X	  depth = 0;
X	  (void) make_target(comm,cursr,curvar[0]);
X      
X	  if (!reallydone)
X	    printf("shape - `%s' is up to date\n", comm);
X      
X	  if (comm != firsttarget)
X	    comm = cmdtargets[k++];
X	  else
X	    comm = NIL;
X	}
X    }
X  else
X    {
X      depth = 0;
X      (void) make_target(rbtarg,cursr,curvar[0]);
X      if (!reallydone)
X	printf("shape - `%s' is up to date\n");
X    }
X}
X
X
X
XBool make_target(targ, sr, vname)
X     char *targ;
X     char *sr;
X     /*ARGSUSED*/
X     char *vname;
X{
X  struct rules *current;
X  char *curdep;
X  char *point = NIL;
X  char *srcname;
X  char dep2[MAXNAMLEN];
X  Bool err_happ = FALSE;
X  Bool todo = FALSE;
X  Bool test = FALSE;
X  Bool t1 = FALSE;
X  char lselrule[64];
X  char lvar[64];
X  char lvarname[64];
X  char *xxx;
X  Bool lbusy_done = FALSE;
X  char path1[MAXNAMLEN];
X  int dep = 0;
X  int curi = 0;
X
X  depth++;
X
X  (void) is_selrule_name(sr);
X
X  (void) strcpy(lselrule,sr);
X  
X  if ((current = get_target(targ)) == (struct rules *) NIL)
X    {
X      if (!exists_file(targ,0))
X	errexit(3,targ);
X      else
X	{
X	  if(strcmp(targ,lastcurdep))
X	    {
X	      if(evtl_set_busy(targ,TRUE))
X		{
X		  (void) strcpy(lastcurdep,targ);
X		  (void) strcpy(sr,lselrule);
X		  return(TRUE);
X		}
X	    }
X	  else
X	    return (FALSE);
X	}
X    }
X
X  if (current->done)
X    {
X      (void) strcpy(sr,lselrule);
X      return(FALSE);
X    }
X  
X  if ((current->deplist[dep] == NIL) && (exists_file(current->name,0)))
X    {
X      (void) strcpy(sr,lselrule);
X      return(FALSE);
X    }
X
X  lbusy_done = busy_done;
X  
X  if (current->deplist[dep] != NIL)
X    {
X      if (is_selrule_name(current->deplist[dep]))
X	{
X	  (void) strcpy(lselrule,current->deplist[dep]);
X	  if ((xxx = index(lselrule,'+')) != NIL)
X	    *xxx = '\0';
X	  (void) strcpy(sr,lselrule);
X	  (void) strcpy(cursr,sr);
X	  dep++;
X	}
X      while(is_varname(current->deplist[dep]))
X	{
X	  (void) strcpy(lvarname,current->deplist[dep]);
X	  if ((xxx = index(lvarname,'+')) != NIL)
X	    {
X	      xxx++;
X	      (void) strcpy(lvarname,xxx);
X	    }
X	  (void) strcpy(lvar,lvarname);
X	  curi = 0;
X	  while(strcmp(curvar[curi],""))
X	    curi++;
X	  if(curi == 32)
X	    errexit(37,NIL);
X	  if ((curvar[curi] = malloc((unsigned) (strlen(lvarname)+sizeof(char)))) == NIL)
X	    errexit(10,"malloc");
X	  variants_active = curi;
X	  (void) strcpy(curvar[curi],lvarname);
X	  (void) attrvar(lvar, NIL, (Af_set *) NIL);
X	  dep++;
X	}
X    }
X  else
X    todo = TRUE;
X  
X  curdep = current->deplist[dep++];
X
X  if(curdep != NIL)
X    {
X      if(!strcmp(curdep,"+"))
X	curdep = current->deplist[dep++];
X    }
X  
X  if (current->name[0] != '%')
X    {
X      if (curdep == NIL)
X	todo = TRUE;
X
X      while (curdep != NIL)
X	{
X	  t1 = exists_file(curdep,0);
X
X	  if ((t1) && (strcmp(curdep,lastcurdep)))
X	    {
X	      (void) strcpy(lastcurdep,curdep);
X	      (void) evtl_set_busy(curdep,TRUE);
X	    }
X
X	  test = make_target(curdep,sr,NIL);
X	  if (error_happened)
X	    {
X	      err_happ = TRUE;
X	      error_happened = FALSE;
X	    }
X	  depth--;
X	  (void) strcat(longattrs[depth], longattrs[depth+1]);
X	  (void) strcpy(longattrs[depth+1],"");
X
X	  if (is_selrule_name(current->firstdep))
X	    {
X	      (void) strcpy(lselrule,current->firstdep);
X	      (void) strcpy(cursr,lselrule);
X	      (void) strcpy(sr,lselrule);
X	    }
X	  while(is_varname(current->deplist[dep]))
X	    {
X	      (void) strcpy(lvarname,current->deplist[dep]);
X	      if ((xxx = index(lvarname,'+')) != NIL)
X		{
X		  xxx++;
X		  (void) strcpy(lvarname,xxx);
X		}
X	      (void) strcpy(lvar,lvarname);
X	      curi = 0;
X	      while(strcmp(curvar[curi],""))
X		curi++;
X	      if(curi == 32)
X		errexit(37,NIL);
X	      if ((curvar[curi] = malloc((unsigned) (strlen(lvarname)+sizeof(char)))) == NIL)
X		errexit(10,"malloc");
X	      variants_active = curi;
X	      (void) strcpy(curvar[curi],lvarname);
X	      (void) attrvar(lvarname, NIL, (Af_set *) NIL);
X	    }
X
X	  if (test)
X	    todo = TRUE;
X	  t1 = exists_file(current->name,0);
X	  (void) strcpy(path1,actpath);
X	  (void) strcpy(actpath,"");
X	  if (!t1)
X	    todo = TRUE;
X	  if (!todo)
X	    {
X	      (void) strcpy(lselrule,cursr);
X	      (void) strcpy(cursr,"-STD-");
X/*	      if (Sselect(current->name, path1, t1, current->deplist[0],curdep))
X		todo = TRUE; */
X	      todo = TRUE;
X	      (void) is_selrule_name(lselrule);
X	      (void) strcpy(cursr,lselrule);
X	    }
X	  curdep = current->deplist[dep++];
X
X	}
X      current->done = TRUE;
X      
X      if ((!todo) && (current->cmdlist == (struct cmds *) NIL))
X	{
X	  srcname = get_src_name(current->name);
X	  if (srcname != NIL)
X	    {
X/*	      if (Sselect(current->name, path1, t1, current->deplist[0],srcname)) */
X		todo = TRUE;
X	      if (TRUE) /* (strcmp(sr,"-STD-")) */
X		{
X		  if (evtl_set_busy(srcname,TRUE))
X		    {
X		      todo = TRUE;
X		      lbusy_done = busy_done;
X		    }
X		} 
X	    }
X	}
X    }
X  
X  if(current->name[0] == '%')
X    {
X/*      if(strcmp(cursr,"-STD-"))
X	{
X	(void) strcpy(dep2,current_dep);
X	  if((evtl_set_busy(dep2) != TRUE)) 
X	    ;
X	  else
X	    errexit(17,current_dep);
X	} */
X      
X      (void) strcpy(dep2, current_dep);
X      point = rindex(dep2,'.');
X      if(point != NIL)
X	*point = '\0';
X      (void) strcat(dep2,current->deplist[0]+1);
X      
X      t1 = exists_file(current_dep,0);
X      if(t1)
X	{
X	  if(lbusy_done) /* ((strcmp(cursr,"-STD-")) && (lbusy_done)) */
X	    {
X	      if (exists_file(dep2,0))
X		{
X		  if (err_happ)
X		    {
X		      warning(2,current->name);
X		      err_happ = FALSE;
X		    }
X		  else
X		    test = execute_commands(current, current_dep, todo);
X		}
X	      busy_done = FALSE;
X	    }
X	  else
X	    {
X/*	      if (Sselect(current_dep, actpath, t1, NIL, dep2)) */
X	      if (TRUE)
X		{
X		  if (exists_file(dep2,0))
X		    {
X		      if (err_happ)
X			{
X			  warning(2, current->name);
X			  err_happ = FALSE;
X			}
X		      else
X			test = execute_commands(current, current_dep, todo);
X		    }
X		}
X	    }
X	}
X      else
X	{
X	  if (exists_file(dep2,0))
X	    {
X	      if (err_happ)
X		{
X		  warning(2, current->name);
X		  err_happ = FALSE;
X		}
X	      else
X		test = execute_commands(current, current_dep, todo);
X	    }
X	}
X      (void) strcpy(current_dep,"");
X    }
X  
X  if (todo)
X    {
X      if (err_happ)
X	{
X	  warning(2, current->name);
X	  err_happ = FALSE;
X	}
X      else
X	test = execute_commands(current, NIL, todo);
X      /* if((!test) && (!noexflg) && (!exists_file(current->name,1)))
X	errexit(3,current->name);
X      
X      if((!test) && (noexflg) && (current->cmdlist == (struct cmds *) NIL))
X	errexit(3,current->name); */
X
X      if(strcmp(lselrule,""))
X	(void) strcpy(sr,lselrule);
X      return(TRUE);
X    }
X  
X  if (test || todo)
X    {
X      if(strcmp(lselrule,""))
X	(void) strcpy(sr,lselrule);
X      return(TRUE);
X    }
X  else
X    {
X      if(strcmp(lselrule,""))
X	(void) strcpy(sr,lselrule);
X      return(FALSE);
X    }
X}
X
X
X
XBool execute_commands(current, rel_dep, doit)
X     struct rules *current;
X     char *rel_dep;
X     Bool doit;
X{
X  struct cmds *curcmd;
X  char *expcmd;
X  char *p;
X  char *pp;
X  char targrulename[MAXNAMLEN];
X  char file[MAXNAMLEN];
X  struct rules *cursuf;
X  Bool exists = FALSE;
X  Bool tx;
X  int retcode;
X  char *mist;
X  char fname[MAXNAMLEN];
X  int i;
X  char attr[MAXATTRLENGTH];
X  
X  attr[0] = '\0';
X  fname[0] = '\0';
X
X  if (rel_dep != NIL)
X    (void) strcpy(file, rel_dep);
X  else
X    (void) strcpy(file, current->name);
X
X  if (current->name[0] == '%')
X    {
X      (void) strcpy(fname, rel_dep);
X      if ((p = rindex(fname,'.')) != NIL)
X	{
X	  *p = '\0';
X	  (void) strcat(fname,current->deplist[0]+1);
X	}
X    }
X
X  if ((current != (struct rules *) NIL) && (current->cmdlist != (struct cmds *) NIL))
X    {
X      /* figure out if derived object already exists */
X#ifndef NOBPOOL
X      tx = exists_file(rel_dep,0);
X      if (!tx)
X	tx = exists_file(current->name,0);
X      if (tx)
X	{
X	  if (rel_dep == NIL)
X	    rel_dep = current->name;
X	  (void) strcpy(attr,build_attrstring(current,rel_dep,(struct rules *) NIL));
X	  retcode = compare_attrstring(attr, current, rel_dep, (struct rules *) NIL);
X	  if ((retcode == 0)) /*  && (!doit)) */
X	    {
X/*	      if(Sselect(rel_dep,actpath,tx,current->deplist[0],fname)) */
X	      return(TRUE); /* FALSE */
X	    }
X	  if ((retcode == 1) && (!doit))
X	    {
X	      return (TRUE);
X	    }
X	}
X#endif NOBPOOL
X      curcmd = current->cmdlist;
X      while (curcmd != (struct cmds *) NIL)
X	{
X	  if (curcmd->command != NIL)
X	    {
X	      if ((mist = malloc(2048)) == NIL)
X		errexit(10,"malloc");
X	      (void) strcpy(mist,expandmacro(curcmd->command));
X	      if ((expcmd = malloc(2048)) == NIL)
X		errexit(10,"malloc");
X	      (void) strcpy(expcmd,expand_command(mist, current, fname));
X	      execute(expcmd);
X	      free(expcmd);
X	      free(mist);
X	    }
X	  else
X	    break;
X	  curcmd = curcmd->nextcmd;
X	}
X      if (current->cmdlist != (struct cmds *) NIL)
X	{
X	  cleanup_links(link_reg);
X	  free_linklist();
X	  link_reg = (struct linkreg *) NIL;
X	}
X
X      if (current->name[0] == '%')
X	{
X	  (void) strcpy(fname, rel_dep);
X	  if ((p = rindex(fname,'.')) != NIL)
X	    {
X	      *p = '\0';
X	      (void) strcat(fname,current->deplist[0]+1);
X	    }
X	  save_targets(current,fname,(struct rules *) NIL,attr);  /* rel_dep */
X	}
X      else
X	{
X	  if (exists_file(current->name,0))
X	    save_targets(current,current->name, (struct rules *) NIL,attr);
X	}
X    } 
X  else
X    { /* execute stdrule or default commands */
X      if ((pp = rindex(current->name,'.')) != NIL)
X	{
X	  (void) strcpy(fname, current->name);
X	  pp = rindex(fname,'.');
X	  *pp = '\0';   /* pp = suffix of target */
X	  (void) strcpy(targrulename,"%.");
X	  (void) strcat(targrulename,pp + 1);
X	  for(i = 0; implicit_suffs[i] != -1; i++)
X	    {
X	      (void) strcpy(fname,current->name);
X	      if ((pp = rindex(fname,'.')) != NIL)
X		*pp = '\0';
X	      /* build source name */
X	      if (strcmp(targrulename, stdruletab[implicit_suffs[i]]->name) == 0)
X		{
X		  /* several dependents may be necessary ???? */
X		  (void) strcat(fname,stdruletab[implicit_suffs[i]]->deplist[0]+1);
X		  
X		  /* source file exists ? */
X		  if(exists_file(fname,0))
X		    {
X		      exists = TRUE;
X		      cursuf = stdruletab[implicit_suffs[i]];
X		      break;
X		    }
X		  else
X		    cursuf = (struct rules *) NIL;
X		}
X	    }
X	  if (exists)
X	    {
X	      /* but first figure out if derived object(s) already exist */
X#ifndef NOBPOOL
X	      tx = exists_file(current->name,0);
X	      if (tx)
X		{
X		  (void) strcpy(attr,build_attrstring(cursuf,fname,current));
X/*		  retcode = compare_attrstring(attr, cursuf, fname, current); */
X		  retcode = compare_attrstring(attr, cursuf, current->name, current);
X		  if((retcode == 0)) /* && (!doit)) */
X		    {
X		      /* if (Sselect(rel_dep,actpath,tx,current->deplist[0],fname)) */
X			return (TRUE); /* FALSE */
X		    }
X		  if ((retcode == 1) && (!doit))
X		    return(TRUE);
X		}
X#endif NOBPOOL
X
X/*	      if (strcmp(cursr,"-STD-"))
X	      (void) evtl_set_busy(fname,TRUE); */
X
X	      (void) strcpy(attr,build_attrstring(cursuf,fname,current));
X	      retcode = compare_attrstring(attr, cursuf, current->name, current);
X	      if (retcode == 0)
X		return(TRUE); /*FALSE */
X
X	      curcmd = cursuf->cmdlist;
X	      while(curcmd != (struct cmds *) NIL)
X		{
X		  if (curcmd->command != NIL)
X		    {
X		      if ((expcmd = malloc(2048)) == NIL)
X			errexit(10,"malloc");
X		      (void) strcpy(expcmd,expandmacro(curcmd->command));
X		      (void) strcpy(expcmd,expand_command(expcmd, current, fname)); /* file */
X		      execute(expcmd);
X		      free(expcmd);
X		    }
X		  else
X		    break;
X		  curcmd = curcmd->nextcmd;
X		}
X	      if (cursuf->cmdlist != (struct cmds *) NIL)
X		{
X		  cleanup_links(link_reg);
X		  free_linklist();
X		  link_reg = (struct linkreg *) NIL;
X		}
X	      save_targets(cursuf,fname,current,attr);
X
X	      /* put derived objects into bpool */
X	      /* and save special attributes */
X
X	    }
X	}
X    }
X  if (cursuf != (struct rules *) NIL)
X    return(TRUE);
X  else
X    return (FALSE);
X}
X
X  
X
Xint execute(cmd)
X     char *cmd;
X{
X  int retcode = 0;
X  Bool ignflg = FALSE;
X  char *rc;
X  Bool silflg;
X
X  cmd = repl_string(cmd);
X  
X  silflg = silentflg;
X
X  while((cmd[0] == '\t') || (cmd[0] == ' ') || (cmd[0] == '\n'))
X    *cmd++;
X
X  if (noexflg)
X    {
X      printf("%s\n", cmd);
X      (void) fflush(stdout);
X      reallydone = TRUE;
X    }
X  else
X    {
X      if (cmd[0] == '@')
X	{
X	  cmd[0] = ' ';
X	  silflg = TRUE;
X	  if (cmd[1] == '-')
X	    {
X	      cmd[1] = ' ';
X	      ignflg = TRUE;
X	    }
X	}
X      if (!silflg)
X	{
X	  printf("shape - executing: %s\n", cmd);
X	  (void) fflush(stdout);
X	}
X      if (!touchflg)
X	{
X	  reallydone = TRUE;
X	  retcode = system(cmd);
X/*	  cleanup_links(link_reg);
X	  free_linklist();
X	  link_reg = (struct linkreg *) NIL; */
X	  if (retcode != 0)
X	    {
X	      error_happened = TRUE;
X	      error_occ = TRUE;
X	      if ((rc = malloc(10 * sizeof(char))) == NIL)
X		errexit(10,"malloc");
X	      (void) sprintf(rc, "%d", retcode); 
X	      if ((ignflg == FALSE) && (goflg == FALSE))
X		errexit(13,rc);
X	      if (goflg == FALSE)
X		errexit(13,rc);
X	    }
X	}
X    }
X  free(cmd);
X}
X
X
Xchar *get_src_name(name)
X     char *name;
X{
X  int i;
X  char fname[MAXNAMLEN];
X  char *p;
X  (void) strcpy(fname,name);
X  if ((p = rindex(fname,'.')) != NIL)
X    {
X      for (i = 0; implicit_suffs[i] != -1; i++)
X	{
X	  *p = '\0';
X	  if (!strcmp(stdruletab[implicit_suffs[i]]->name+2,p+1))
X	    {
X	      (void) strcat(fname,stdruletab[implicit_suffs[i]]->deplist[0]+1);
X	      if (exists_file(fname,0))
X		return(fname);
X	    }
X	}
X      if(implicit_suffs[i] == -1)
X	return(NIL);
X    }
X  /*NOTREACHED*/
X  return(NIL);
X}
X       
X
Xset_pathi()
X{
X  int i = 0;
X  while(curvpath[i] != NIL)
X    i++;
X  pathi = i;
X}
END_OF_FILE
if test 27571 -ne `wc -c <'src/shape/produce.c'`; then
    echo shar: \"'src/shape/produce.c'\" unpacked with wrong size!
fi
# end of 'src/shape/produce.c'
fi
echo shar: End of archive 25 \(of 33\).
cp /dev/null ark25isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 33 archives.
    rm -f ark[1-9]isdone ark[1-9][0-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0
-- 
Please send comp.sources.unix-related mail to rsalz@uunet.uu.net.