home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 4
/
FreshFish_May-June1994.bin
/
bsd
/
src
/
make
/
make-amiga
/
parse.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-09-23
|
60KB
|
2,213 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[] = "@(#)parse.c 5.18 (Berkeley) 2/19/91";
#endif /* not lint */
/*-
* parse.c --
* Functions to parse a makefile.
*
* One function, Parse_Init, must be called before any functions
* in this module are used. After that, the function Parse_File is the
* main entry point and controls most of the other functions in this
* module.
*
* Most important structures are kept in Lsts. Directories for
* the #include "..." function are kept in the 'parseIncPath' Lst, while
* those for the #include <...> are kept in the 'sysIncPath' Lst. The
* targets currently being defined are kept in the 'targets' Lst.
*
* The variables 'fname' and 'lineno' are used to track the name
* of the current file and the line number in that file so that error
* messages can be more meaningful.
*
* Interface:
* Parse_Init Initialization function which must be
* called before anything else in this module
* is used.
*
* Parse_File Function used to parse a makefile. It must
* be given the name of the file, which should
* already have been opened, and a function
* to call to read a character from the file.
*
* Parse_IsVar Returns TRUE if the given line is a
* variable assignment. Used by MainParseArgs
* to determine if an argument is a target
* or a variable assignment. Used internally
* for pretty much the same thing...
*
* Parse_Error Function called when an error occurs in
* parsing. Used by the variable and
* conditional modules.
* Parse_MainName Returns a Lst of the main target to create.
*/
#include <varargs.h>
#include <stdio.h>
#include <ctype.h>
#include "make.h"
#include "buf.h"
#include "pathnames.h"
/*
* These values are returned by ParseEOF to tell Parse_File whether to
* CONTINUE parsing, i.e. it had only reached the end of an include file,
* or if it's DONE.
*/
#define CONTINUE 1
#define DONE 0
static int ParseEOF();
static Lst targets; /* targets we're working on */
static Boolean inLine; /* true if currently in a dependency
* line or its commands */
static char *fname; /* name of current file (for errors) */
static int lineno; /* line number in current file */
static FILE *curFILE; /* current makefile */
static int fatals = 0;
static GNode *mainNode; /* The main target to create. This is the
* first target on the first dependency
* line in the first makefile */
/*
* Definitions for handling #include specifications
*/
typedef struct IFile {
char *fname; /* name of previous file */
int lineno; /* saved line number */
FILE * F; /* the open stream */
} IFile;
static Lst includes; /* stack of IFiles generated by
* #includes */
Lst parseIncPath; /* list of directories for "..." includes */
Lst sysIncPath; /* list of directories for <...> includes */
/*-
* specType contains the SPECial TYPE of the current target. It is
* Not if the target is unspecial. If it *is* special, however, the children
* are linked as children of the parent but not vice versa. This variable is
* set in ParseDoDependency
*/
typedef enum {
Begin, /* .BEGIN */
Default, /* .DEFAULT */
End, /* .END */
Ignore, /* .IGNORE */
Includes, /* .INCLUDES */
Interrupt, /* .INTERRUPT */
Libs, /* .LIBS */
MFlags, /* .MFLAGS or .MAKEFLAGS */
Main, /* .MAIN and we don't have anything user-specified to
* make */
Not, /* Not special */
NotParallel, /* .NOTPARALELL */
Null, /* .NULL */
Order, /* .ORDER */
Path, /* .PATH */
Precious, /* .PRECIOUS */
Shell, /* .SHELL */
Silent, /* .SILENT */
SingleShell, /* .SINGLESHELL */
Suffixes, /* .SUFFIXES */
Attribute, /* Generic attribute */
} ParseSpecial;
ParseSpecial specType;
/*
* Predecessor node for handling .ORDER. Initialized to NILGNODE when .ORDER
* seen, then set to each successive source on the line.
*/
static GNode *predecessor;
/*
* The parseKeywords table is searched using binary search when deciding
* if a target or source is special. The 'spec' field is the ParseSpecial
* type of the keyword ("Not" if the keyword isn't special as a target) while
* the 'op' field is the operator to apply to the list of targets if the
* keyword is used as a source ("0" if the keyword isn't special as a source)
*/
static struct {
char *name; /* Name of keyword */
ParseSpecial spec; /* Type when used as a target */
int op; /* Operator when used as a source */
} parseKeywords[] = {
{ ".BEGIN", Begin, 0 },
{ ".DEFAULT", Default, 0 },
{ ".OPTIONAL", Attribute, OP_OPTIONAL },
{ ".END", End, 0 },
{ ".EXEC", Attribute, OP_EXEC },
{ ".IGNORE", Ignore, OP_IGNORE },
{ ".INCLUDES", Includes, 0 },
{ ".INTERRUPT", Interrupt, 0 },
{ ".INVISIBLE", Attribute, OP_INVISIBLE },
{ ".JOIN", Attribute, OP_JOIN },
{ ".LIBS", Libs, 0 },
{ ".MAIN", Main, 0 },
{ ".MAKE", Attribute, OP_MAKE },
{ ".MAKEFLAGS", MFlags, 0 },
{ ".MFLAGS", MFlags, 0 },
{ ".NOTMAIN", Attribute, OP_NOTMAIN },
{ ".NOTPARALLEL", NotParallel, 0 },
{ ".NULL", Null, 0 },
{ ".ORDER", Order, 0 },
{ ".PATH", Path, 0 },
{ ".PRECIOUS", Precious, OP_PRECIOUS },
{ ".RECURSIVE", Attribute, OP_MAKE },
{ ".SHELL", Shell, 0 },
{ ".SILENT", Silent, OP_SILENT },
{ ".SINGLESHELL", SingleShell, 0 },
{ ".SUFFIXES", Suffixes, 0 },
{ ".USE", Attribute, OP_USE },
};
/*-
*----------------------------------------------------------------------
* ParseFindKeyword --
* Look in the table of keywords for one matching the given string.
*
* Results:
* The index of the keyword, or -1 if it isn't there.
*
* Side Effects:
* None
*------------------