home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 4
/
FreshFish_May-June1994.bin
/
bsd
/
src
/
make
/
make-amiga
/
suff.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-09-23
|
61KB
|
2,160 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[] = "@(#)suff.c 5.6 (Berkeley) 6/1/90";
#endif /* not lint */
/*-
* suff.c --
* Functions to maintain suffix lists and find implicit dependents
* using suffix transformation rules
*
* Interface:
* Suff_Init Initialize all things to do with suffixes.
*
* Suff_DoPaths This function is used to make life easier
* when searching for a file according to its
* suffix. It takes the global search path,
* as defined using the .PATH: target, and appends
* its directories to the path of each of the
* defined suffixes, as specified using
* .PATH<suffix>: targets. In addition, all
* directories given for suffixes labeled as
* include files or libraries, using the .INCLUDES
* or .LIBS targets, are played with using
* Dir_MakeFlags to create the .INCLUDES and
* .LIBS global variables.
*
* Suff_ClearSuffixes Clear out all the suffixes and defined
* transformations.
*
* Suff_IsTransform Return TRUE if the passed string is the lhs
* of a transformation rule.
*
* Suff_AddSuffix Add the passed string as another known suffix.
*
* Suff_GetPath Return the search path for the given suffix.
*
* Suff_AddInclude Mark the given suffix as denoting an include
* file.
*
* Suff_AddLib Mark the given suffix as denoting a library.
*
* Suff_AddTransform Add another transformation to the suffix
* graph. Returns GNode suitable for framing, I
* mean, tacking commands, attributes, etc. on.
*
* Suff_SetNull Define the suffix to consider the suffix of
* any file that doesn't have a known one.
*
* Suff_FindDeps Find implicit sources for and the location of
* a target based on its suffix. Returns the
* bottom-most node added to the graph or NILGNODE
* if the target had no implicit sources.
*/
#include <stdio.h>
#include "make.h"
#include "bit.h"
static Lst sufflist; /* Lst of suffixes */
static Lst transforms; /* Lst of transformation rules */
static int sNum = 0; /* Counter for assigning suffix numbers */
/*
* Structure describing an individual suffix.
*/
typedef struct _Suff {
char *name; /* The suffix itself */
int nameLen; /* Length of the suffix */
short flags; /* Type of suffix */
#define SUFF_INCLUDE 0x01 /* One which is #include'd */
#define SUFF_LIBRARY 0x02 /* One which contains a library */
#define SUFF_NULL 0x04 /* The empty suffix */
Lst searchPath; /* The path along which files of this suffix
* may be found */
int sNum; /* The suffix number */
Lst parents; /* Suffixes we have a transformation to */
Lst children; /* Suffixes we have a transformation from */
} Suff;
/*
* Structure used in the search for implied sources.
*/
typedef struct _Src {
char *file; /* The file to look for */
char *pref; /* Prefix from which file was formed */
Suff *suff; /* The suffix on the file */
struct _Src *parent; /* The Src for which this is a source */
GNode *node; /* The node describing the file */
int children; /* Count of existing children (so we don't free
* this thing too early or never nuke it) */
} Src;
static Suff *suffNull; /* The NULL suffix for this run */
static Suff *emptySuff; /* The empty suffix required for POSIX
* single-suffix transformation rules */
/*************** Lst Predicates ****************/
/*-
*-----------------------------------------------------------------------
* SuffStrIsPrefix --
* See if pref is a prefix of str.
*
* Results:
* NULL if it ain't, pointer to character in str after prefix if so
*
* Side Effects:
* None
*-----------------------------------------------------------------------
*/
static char *
SuffStrIsPrefix (pref, str)
register char *pref; /* possible prefix */
register char *str; /* string to check */
{
while (*str && *pref == *str) {
pref++;
str++;
}
return (*pref ? NULL : str);
}
/*-
*-----------------------------------------------------------------------
* SuffSuffIsSuffix --
* See if suff is a suffix of str. Str should point to THE END of the
* string to check. (THE END == the null byte)
*
* Results:
* NULL if it ain't, pointer to character in str before suffix if
* it is.
*
* Side Effects:
* None
*-----------------------------------------------------------------------
*/
static char *
SuffSuffIsSuffix (s, str)
register Suff *s; /* possible suffix */
char *str; /* string to examine */
{
register char *p1; /* Pointer into suffix name */
register char *p2; /* Pointer into string being examined */
p1 = s->name + s->nameLen;
p2 = str;
while (p1 >= s->name && *p1 == *p2) {
p1--;
p2--;
}
return (p1 == s->name - 1 ? p2 : NULL);
}
/*-
*-----------------------------------------------------------------------
* SuffSuffIsSuffixP --
* Predicate form of SuffSuffIsSuffix. Passed as the callback function
* to Lst_Find.
*
* Results:
* 0 if the suffix is the one desired, non-zero if not.
*
* Side Effects:
* None.
*
*-----------------------------------------------------------------------
*/
SuffSuffIsSuffixP(s, str)
Suff *s;
char *str;
{
return(!SuffSuffIsSuffix(s, str));
}
/*-
*-----------------------------------------------------------------------
* SuffSuffHasNameP --
* Callback procedure for finding a suffix based on its name. Used by
* Suff_GetPath.
*
* Results:
* 0 if the suffix is of the given name. non-zero otherwise.
*
* Side Effects:
* None
*-----------------------------------------------------------------------
*/
static int
SuffSuffHasNameP (s, sname)
Suff *s; /* Suffix to check */
char *sname; /* Desired name */
{
return (strcmp (sname, s