home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 4
/
FreshFish_May-June1994.bin
/
bsd
/
src
/
make
/
make-amiga
/
targ.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-09-23
|
16KB
|
582 lines
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
* Copyright (c) 1988, 1989 by Adam de Boor
* Copyright (c) 1989 by Berkeley Softworks
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Adam de Boor.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef lint
static char sccsid[] = "@(#)targ.c 5.9 (Berkeley) 3/1/91";
#endif /* not lint */
/*-
* targ.c --
* Functions for maintaining the Lst allTargets. Target nodes are
* kept in two structures: a Lst, maintained by the list library, and a
* hash table, maintained by the hash library.
*
* Interface:
* Targ_Init Initialization procedure.
*
* Targ_NewGN Create a new GNode for the passed target
* (string). The node is *not* placed in the
* hash table, though all its fields are
* initialized.
*
* Targ_FindNode Find the node for a given target, creating
* and storing it if it doesn't exist and the
* flags are right (TARG_CREATE)
*
* Targ_FindList Given a list of names, find nodes for all
* of them. If a name doesn't exist and the
* TARG_NOCREATE flag was given, an error message
* is printed. Else, if a name doesn't exist,
* its node is created.
*
* Targ_Ignore Return TRUE if errors should be ignored when
* creating the given target.
*
* Targ_Silent Return TRUE if we should be silent when
* creating the given target.
*
* Targ_Precious Return TRUE if the target is precious and
* should not be removed if we are interrupted.
*
* Debugging:
* Targ_PrintGraph Print out the entire graphm all variables
* and statistics for the directory cache. Should
* print something for suffixes, too, but...
*/
#include <stdio.h>
#include <time.h>
#include "make.h"
#include "hash.h"
static Lst allTargets; /* the list of all targets found so far */
static Hash_Table targets; /* a hash table of same */
#define HTSIZE 191 /* initial size of hash table */
/*-
*-----------------------------------------------------------------------
* Targ_Init --
* Initialize this module
*
* Results:
* None
*
* Side Effects:
* The allTargets list and the targets hash table are initialized
*-----------------------------------------------------------------------
*/
void
Targ_Init ()
{
allTargets = Lst_Init (FALSE);
Hash_InitTable (&targets, HTSIZE);
}
/*-
*-----------------------------------------------------------------------
* Targ_NewGN --
* Create and initialize a new graph node
*
* Results:
* An initialized graph node with the name field filled with a copy
* of the passed name
*
* Side Effects:
* None.
*-----------------------------------------------------------------------
*/
GNode *
Targ_NewGN (name)
char *name; /* the name to stick in the new node */
{
register GNode *gn;
gn = (GNode *) emalloc (sizeof (GNode));
gn->name = strdup (name);
gn->path = (char *) 0;
if (name[0] == '-' && name[1] == 'l') {
gn->type = OP_LIB;
} else {
gn->type = 0;
}
gn->unmade = 0;
gn->make = FALSE;
gn->made = UNMADE;
gn->childMade = FALSE;
gn->mtime = gn->cmtime = 0;
gn->iParents = Lst_Init (FALSE);
gn->cohorts = Lst_Init (FALSE);
gn->parents = Lst_Init (FALSE);
gn->children = Lst_Init (FALSE);
gn->successors = Lst_Init(FALSE);
gn->preds = Lst_Init(FALSE);
gn->context = Lst_Init (FALSE);
gn->commands = Lst_Init (FALSE);
return (gn);
}
/*-
*-----------------------------------------------------------------------
* Targ_FindNode --
* Find a node in the list using the given name for matching
*
* Results:
* The node in the list if it was. If it wasn't, return NILGNODE of
* flags was TARG_NOCREATE or the newly created and initialized node
* if it was TARG_CREATE
*
* Side Effects:
* Sometimes a node is created and added to the list
*-----------------------------------------------------------------------
*/
GNode *
Targ_FindNode (name, flags)
char *name; /* the name to find */
int flags; /* flags governing events when target not
* found */
{
GNode *gn; /* node in that element */
Hash_Entry *he; /* New or used hash entry for node */
Boolean isNew; /* Set TRUE if Hash_CreateEntry had to create */
/* an entry for the node */
if (flags & TARG_CREATE) {
he = Hash_CreateEntry (&targets, name, &isNew);
if (isNew) {
gn = Targ_NewGN (name);
Hash_SetValue (he, gn);
(void) Lst_AtEnd (allTargets, (ClientData)gn);
}
} else {
he = Hash_FindEntry (&targets, name);
}
if (he == (Hash_Entry *) NULL) {
return (NILGNODE);
} else {
return ((GNode *) Hash_GetValue (he));
}
}
/*-
*-----------------------------------------------------------------------
* Targ_FindList --
* Make a complete list of GNodes from the given list of names
*
* Results:
* A complete list of graph nodes corresponding to all instances of all
* the names in names.
*
* Side Effects:
* If flags is TARG_CREATE, nodes will be created for all names in
* names which do not yet have graph nodes. If flags is TARG_NOCREATE,
* an error message will be printed for each name which can't be found.
* -----------------------------------------------------------------------
*/
Lst
Targ_FindList (names, flags)
Lst names; /* list of names to find */
int flags; /* flags used if no node is found for a given
* name */
{
Lst nodes; /* result list */
register LstNode ln; /* name list element */
register GNode *gn; /* node in tLn */
char *name;
nodes = Lst_Init (FALSE);
if (Lst_Open (names) == FAILURE) {
return (nodes);
}
while ((ln = Lst_Next (names)) != NILLNODE) {
name = (char *)Lst_Datum(ln);
gn = Targ_FindNode (name, flags);
if (gn != NILGNODE) {
/*
* Note: Lst_AtEnd must come before the Lst_Concat so the nodes
* are added to the list in the order in which they were
* encountered in the makefile.
*/
(void) Lst_AtEnd (nodes, (ClientData)gn);
if (gn->type & OP_DOUBLEDEP) {
(void)Lst_Concat (nodes, gn->cohorts, LST_CONCNEW);
}
} else if (flags == TARG_NOCREATE) {