140395Sbostic /* 240395Sbostic * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. 340395Sbostic * Copyright (c) 1988, 1989 by Adam de Boor 440395Sbostic * Copyright (c) 1989 by Berkeley Softworks 540395Sbostic * All rights reserved. 640395Sbostic * 740395Sbostic * This code is derived from software contributed to Berkeley by 840395Sbostic * Adam de Boor. 940395Sbostic * 1040395Sbostic * Redistribution and use in source and binary forms are permitted 1140395Sbostic * provided that the above copyright notice and this paragraph are 1240395Sbostic * duplicated in all such forms and that any documentation, 1340395Sbostic * advertising materials, and other materials related to such 1440395Sbostic * distribution and use acknowledge that the software was developed 1540395Sbostic * by the University of California, Berkeley. The name of the 1640395Sbostic * University may not be used to endorse or promote products derived 1740395Sbostic * from this software without specific prior written permission. 1840395Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 1940395Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 2040395Sbostic * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 2140395Sbostic */ 2240395Sbostic 2340395Sbostic #ifndef lint 24*40439Sbostic static char sccsid[] = "@(#)parse.c 5.5 (Berkeley) 03/12/90"; 2540395Sbostic #endif /* not lint */ 2640395Sbostic 2740393Sbostic /*- 2840393Sbostic * parse.c -- 2940393Sbostic * Functions to parse a makefile. 3040393Sbostic * 3140393Sbostic * One function, Parse_Init, must be called before any functions 3240393Sbostic * in this module are used. After that, the function Parse_File is the 3340393Sbostic * main entry point and controls most of the other functions in this 3440393Sbostic * module. 3540393Sbostic * 3640393Sbostic * Most important structures are kept in Lsts. Directories for 3740393Sbostic * the #include "..." function are kept in the 'parseIncPath' Lst, while 3840393Sbostic * those for the #include <...> are kept in the 'sysIncPath' Lst. The 3940393Sbostic * targets currently being defined are kept in the 'targets' Lst. 4040393Sbostic * 4140393Sbostic * The variables 'fname' and 'lineno' are used to track the name 4240393Sbostic * of the current file and the line number in that file so that error 4340393Sbostic * messages can be more meaningful. 4440393Sbostic * 4540393Sbostic * Interface: 4640393Sbostic * Parse_Init Initialization function which must be 4740393Sbostic * called before anything else in this module 4840393Sbostic * is used. 4940393Sbostic * 5040393Sbostic * Parse_File Function used to parse a makefile. It must 5140393Sbostic * be given the name of the file, which should 5240393Sbostic * already have been opened, and a function 5340393Sbostic * to call to read a character from the file. 5440393Sbostic * 5540393Sbostic * Parse_IsVar Returns TRUE if the given line is a 5640393Sbostic * variable assignment. Used by MainParseArgs 5740393Sbostic * to determine if an argument is a target 5840393Sbostic * or a variable assignment. Used internally 5940393Sbostic * for pretty much the same thing... 6040393Sbostic * 6140393Sbostic * Parse_Error Function called when an error occurs in 6240393Sbostic * parsing. Used by the variable and 6340393Sbostic * conditional modules. 6440393Sbostic * Parse_MainName Returns a Lst of the main target to create. 6540393Sbostic */ 6640393Sbostic 6740393Sbostic #include <stdio.h> 6840393Sbostic #include <ctype.h> 6940393Sbostic #include "make.h" 7040393Sbostic #include "buf.h" 7140393Sbostic 7240393Sbostic /* 7340393Sbostic * These values are returned by ParseEOF to tell Parse_File whether to 7440393Sbostic * CONTINUE parsing, i.e. it had only reached the end of an include file, 7540393Sbostic * or if it's DONE. 7640393Sbostic */ 7740393Sbostic #define CONTINUE 1 7840393Sbostic #define DONE 0 7940393Sbostic static int ParseEOF(); 8040393Sbostic 8140393Sbostic static Lst targets; /* targets we're working on */ 8240393Sbostic static Boolean inLine; /* true if currently in a dependency 8340393Sbostic * line or its commands */ 8440393Sbostic 8540393Sbostic static char *fname; /* name of current file (for errors) */ 8640393Sbostic static int lineno; /* line number in current file */ 8740393Sbostic static FILE *curFILE; /* current makefile */ 8840393Sbostic 8940393Sbostic static int fatals = 0; 9040393Sbostic 9140393Sbostic static GNode *mainNode; /* The main target to create. This is the 9240393Sbostic * first target on the first dependency 9340393Sbostic * line in the first makefile */ 9440393Sbostic /* 9540393Sbostic * Definitions for handling #include specifications 9640393Sbostic */ 9740393Sbostic typedef struct IFile { 9840393Sbostic char *fname; /* name of previous file */ 9940393Sbostic int lineno; /* saved line number */ 10040393Sbostic FILE * F; /* the open stream */ 10140393Sbostic } IFile; 10240393Sbostic 10340393Sbostic static Lst includes; /* stack of IFiles generated by 10440393Sbostic * #includes */ 10540393Sbostic Lst parseIncPath; /* list of directories for "..." includes */ 10640393Sbostic Lst sysIncPath; /* list of directories for <...> includes */ 10740393Sbostic 10840393Sbostic /*- 10940393Sbostic * specType contains the SPECial TYPE of the current target. It is 11040393Sbostic * Not if the target is unspecial. If it *is* special, however, the children 11140393Sbostic * are linked as children of the parent but not vice versa. This variable is 11240393Sbostic * set in ParseDoDependency 11340393Sbostic */ 11440393Sbostic typedef enum { 11540393Sbostic Begin, /* .BEGIN */ 11640393Sbostic Default, /* .DEFAULT */ 11740393Sbostic End, /* .END */ 11840393Sbostic Ignore, /* .IGNORE */ 11940393Sbostic Includes, /* .INCLUDES */ 12040393Sbostic Interrupt, /* .INTERRUPT */ 12140393Sbostic Libs, /* .LIBS */ 12240393Sbostic MFlags, /* .MFLAGS or .MAKEFLAGS */ 12340393Sbostic Main, /* .MAIN and we don't have anything user-specified to 12440393Sbostic * make */ 12540393Sbostic Not, /* Not special */ 12640393Sbostic NotParallel, /* .NOTPARALELL */ 12740393Sbostic Null, /* .NULL */ 12840393Sbostic Order, /* .ORDER */ 12940393Sbostic Path, /* .PATH */ 13040393Sbostic Precious, /* .PRECIOUS */ 13140393Sbostic Shell, /* .SHELL */ 13240393Sbostic Silent, /* .SILENT */ 13340393Sbostic SingleShell, /* .SINGLESHELL */ 13440393Sbostic Suffixes, /* .SUFFIXES */ 13540393Sbostic Attribute, /* Generic attribute */ 13640393Sbostic } ParseSpecial; 13740393Sbostic 13840393Sbostic ParseSpecial specType; 13940393Sbostic 14040393Sbostic /* 14140393Sbostic * Predecessor node for handling .ORDER. Initialized to NILGNODE when .ORDER 14240393Sbostic * seen, then set to each successive source on the line. 14340393Sbostic */ 14440393Sbostic static GNode *predecessor; 14540393Sbostic 14640393Sbostic /* 14740393Sbostic * The parseKeywords table is searched using binary search when deciding 14840393Sbostic * if a target or source is special. The 'spec' field is the ParseSpecial 14940393Sbostic * type of the keyword ("Not" if the keyword isn't special as a target) while 15040393Sbostic * the 'op' field is the operator to apply to the list of targets if the 15140393Sbostic * keyword is used as a source ("0" if the keyword isn't special as a source) 15240393Sbostic */ 15340393Sbostic static struct { 15440393Sbostic char *name; /* Name of keyword */ 15540393Sbostic ParseSpecial spec; /* Type when used as a target */ 15640393Sbostic int op; /* Operator when used as a source */ 15740393Sbostic } parseKeywords[] = { 15840393Sbostic { ".BEGIN", Begin, 0 }, 15940393Sbostic { ".DEFAULT", Default, 0 }, 16040393Sbostic { ".DONTCARE", Attribute, OP_DONTCARE }, 16140393Sbostic { ".END", End, 0 }, 16240393Sbostic { ".EXEC", Attribute, OP_EXEC }, 16340393Sbostic { ".IGNORE", Ignore, OP_IGNORE }, 16440393Sbostic { ".INCLUDES", Includes, 0 }, 16540393Sbostic { ".INTERRUPT", Interrupt, 0 }, 16640393Sbostic { ".INVISIBLE", Attribute, OP_INVISIBLE }, 16740393Sbostic { ".JOIN", Attribute, OP_JOIN }, 16840393Sbostic { ".LIBS", Libs, 0 }, 16940393Sbostic { ".MAIN", Main, 0 }, 17040393Sbostic { ".MAKE", Attribute, OP_MAKE }, 17140393Sbostic { ".MAKEFLAGS", MFlags, 0 }, 17240393Sbostic { ".MFLAGS", MFlags, 0 }, 17340393Sbostic { ".NOTMAIN", Attribute, OP_NOTMAIN }, 17440393Sbostic { ".NOTPARALLEL", NotParallel, 0 }, 17540393Sbostic { ".NULL", Null, 0 }, 17640393Sbostic { ".ORDER", Order, 0 }, 17740393Sbostic { ".PATH", Path, 0 }, 17840393Sbostic { ".PRECIOUS", Precious, OP_PRECIOUS }, 17940393Sbostic { ".RECURSIVE", Attribute, OP_MAKE }, 18040393Sbostic { ".SHELL", Shell, 0 }, 18140393Sbostic { ".SILENT", Silent, OP_SILENT }, 18240393Sbostic { ".SINGLESHELL", SingleShell, 0 }, 18340393Sbostic { ".SUFFIXES", Suffixes, 0 }, 18440393Sbostic { ".USE", Attribute, OP_USE }, 18540393Sbostic }; 18640424Sbostic 18740393Sbostic /*- 18840393Sbostic *---------------------------------------------------------------------- 18940393Sbostic * ParseFindKeyword -- 19040393Sbostic * Look in the table of keywords for one matching the given string. 19140393Sbostic * 19240393Sbostic * Results: 19340393Sbostic * The index of the keyword, or -1 if it isn't there. 19440393Sbostic * 19540393Sbostic * Side Effects: 19640393Sbostic * None 19740393Sbostic *---------------------------------------------------------------------- 19840393Sbostic */ 19940393Sbostic static int 20040393Sbostic ParseFindKeyword (str) 20140393Sbostic char *str; /* String to find */ 20240393Sbostic { 20340393Sbostic register int start, 20440393Sbostic end, 20540393Sbostic cur; 20640393Sbostic register int diff; 20740393Sbostic 20840393Sbostic start = 0; 20940393Sbostic end = (sizeof(parseKeywords)/sizeof(parseKeywords[0])) - 1; 21040393Sbostic 21140393Sbostic do { 21240393Sbostic cur = start + ((end - start) / 2); 21340393Sbostic diff = strcmp (str, parseKeywords[cur].name); 21440393Sbostic 21540393Sbostic if (diff == 0) { 21640393Sbostic return (cur); 21740393Sbostic } else if (diff < 0) { 21840393Sbostic end = cur - 1; 21940393Sbostic } else { 22040393Sbostic start = cur + 1; 22140393Sbostic } 22240393Sbostic } while (start <= end); 22340393Sbostic return (-1); 22440393Sbostic } 22540424Sbostic 22640393Sbostic /*- 22740393Sbostic *--------------------------------------------------------------------- 22840393Sbostic * Parse_Error -- 22940393Sbostic * Error message abort function for parsing. Prints out the context 23040393Sbostic * of the error (line number and file) as well as the message with 23140393Sbostic * two optional arguments. 23240393Sbostic * 23340393Sbostic * Results: 23440393Sbostic * None 23540393Sbostic * 23640393Sbostic * Side Effects: 23740393Sbostic * "fatals" is incremented if the level is PARSE_FATAL. 23840393Sbostic *--------------------------------------------------------------------- 23940393Sbostic */ 24040393Sbostic /* VARARGS1 */ 24140393Sbostic void 24240393Sbostic Parse_Error (type, fmt, arg1, arg2) 24340393Sbostic int type; /* Error type: PARSE_WARNING if just a warning, 24440393Sbostic * PARSE_FATAL if can't continue (after parsing) */ 24540393Sbostic char *fmt; /* printf format string */ 24640393Sbostic int arg1; /* First optional argument for the fmt string */ 24740393Sbostic int arg2; /* Second optional argument for the fmt string */ 24840393Sbostic { 24940393Sbostic if ((type != PARSE_WARNING) || !noWarnings) { 25040393Sbostic fprintf (stderr, "\"%s\", line %d: ", fname, lineno); 25140393Sbostic if (type == PARSE_WARNING) { 25240393Sbostic fprintf (stderr, "Warning: "); 25340393Sbostic } 25440393Sbostic fprintf (stderr, fmt, arg1, arg2); 25540393Sbostic putc ('\n', stderr); 25640393Sbostic 25740393Sbostic if (type == PARSE_FATAL) { 25840393Sbostic fatals += 1; 25940393Sbostic } 26040393Sbostic } 26140393Sbostic } 26240424Sbostic 26340393Sbostic /*- 26440393Sbostic *--------------------------------------------------------------------- 26540393Sbostic * ParseLinkSrc -- 26640393Sbostic * Link the parent node to its new child. Used in a Lst_ForEach by 26740393Sbostic * ParseDoDependency. If the specType isn't 'Not', the parent 26840393Sbostic * isn't linked as a parent of the child. 26940393Sbostic * 27040393Sbostic * Results: 27140393Sbostic * Always = 0 27240393Sbostic * 27340393Sbostic * Side Effects: 27440393Sbostic * New elements are added to the parents list of cgn and the 27540393Sbostic * children list of cgn. the unmade field of pgn is updated 27640393Sbostic * to reflect the additional child. 27740393Sbostic *--------------------------------------------------------------------- 27840393Sbostic */ 27940393Sbostic static int 28040393Sbostic ParseLinkSrc (pgn, cgn) 28140393Sbostic GNode *pgn; /* The parent node */ 28240393Sbostic GNode *cgn; /* The child node */ 28340393Sbostic { 28440393Sbostic if (Lst_Member (pgn->children, (ClientData)cgn) == NILLNODE) { 28540393Sbostic (void)Lst_AtEnd (pgn->children, (ClientData)cgn); 28640393Sbostic if (specType == Not) { 28740393Sbostic (void)Lst_AtEnd (cgn->parents, (ClientData)pgn); 28840393Sbostic } 28940393Sbostic pgn->unmade += 1; 29040393Sbostic } 29140393Sbostic return (0); 29240393Sbostic } 29340424Sbostic 29440393Sbostic /*- 29540393Sbostic *--------------------------------------------------------------------- 29640393Sbostic * ParseDoOp -- 29740393Sbostic * Apply the parsed operator to the given target node. Used in a 29840393Sbostic * Lst_ForEach call by ParseDoDependency once all targets have 29940393Sbostic * been found and their operator parsed. If the previous and new 30040393Sbostic * operators are incompatible, a major error is taken. 30140393Sbostic * 30240393Sbostic * Results: 30340393Sbostic * Always 0 30440393Sbostic * 30540393Sbostic * Side Effects: 30640393Sbostic * The type field of the node is altered to reflect any new bits in 30740393Sbostic * the op. 30840393Sbostic *--------------------------------------------------------------------- 30940393Sbostic */ 31040393Sbostic static int 31140393Sbostic ParseDoOp (gn, op) 31240393Sbostic GNode *gn; /* The node to which the operator is to be 31340393Sbostic * applied */ 31440393Sbostic int op; /* The operator to apply */ 31540393Sbostic { 31640393Sbostic /* 31740393Sbostic * If the dependency mask of the operator and the node don't match and 31840393Sbostic * the node has actually had an operator applied to it before, and 31940393Sbostic * the operator actually has some dependency information in it, complain. 32040393Sbostic */ 32140393Sbostic if (((op & OP_OPMASK) != (gn->type & OP_OPMASK)) && 32240393Sbostic !OP_NOP(gn->type) && !OP_NOP(op)) 32340393Sbostic { 32440393Sbostic Parse_Error (PARSE_FATAL, "Inconsistent operator for %s", gn->name); 32540393Sbostic return (1); 32640393Sbostic } 32740393Sbostic 32840393Sbostic if ((op == OP_DOUBLEDEP) && ((gn->type & OP_OPMASK) == OP_DOUBLEDEP)) { 32940393Sbostic /* 33040393Sbostic * If the node was the object of a :: operator, we need to create a 33140393Sbostic * new instance of it for the children and commands on this dependency 33240393Sbostic * line. The new instance is placed on the 'cohorts' list of the 33340393Sbostic * initial one (note the initial one is not on its own cohorts list) 33440393Sbostic * and the new instance is linked to all parents of the initial 33540393Sbostic * instance. 33640393Sbostic */ 33740393Sbostic register GNode *cohort; 33840393Sbostic LstNode ln; 33940393Sbostic 34040393Sbostic cohort = Targ_NewGN(gn->name); 34140393Sbostic /* 34240393Sbostic * Duplicate links to parents so graph traversal is simple. Perhaps 34340393Sbostic * some type bits should be duplicated? 34440393Sbostic * 34540393Sbostic * Make the cohort invisible as well to avoid duplicating it into 34640393Sbostic * other variables. True, parents of this target won't tend to do 34740393Sbostic * anything with their local variables, but better safe than 34840393Sbostic * sorry. 34940393Sbostic */ 35040393Sbostic Lst_ForEach(gn->parents, ParseLinkSrc, (ClientData)cohort); 35140393Sbostic cohort->type = OP_DOUBLEDEP|OP_INVISIBLE; 35240393Sbostic (void)Lst_AtEnd(gn->cohorts, (ClientData)cohort); 35340393Sbostic 35440393Sbostic /* 35540393Sbostic * Replace the node in the targets list with the new copy 35640393Sbostic */ 35740393Sbostic ln = Lst_Member(targets, (ClientData)gn); 35840393Sbostic Lst_Replace(ln, (ClientData)cohort); 35940393Sbostic gn = cohort; 36040393Sbostic } 36140393Sbostic /* 36240393Sbostic * We don't want to nuke any previous flags (whatever they were) so we 36340393Sbostic * just OR the new operator into the old 36440393Sbostic */ 36540393Sbostic gn->type |= op; 36640393Sbostic 36740393Sbostic return (0); 36840393Sbostic } 36940424Sbostic 37040393Sbostic /*- 37140393Sbostic *--------------------------------------------------------------------- 37240393Sbostic * ParseDoSrc -- 37340393Sbostic * Given the name of a source, figure out if it is an attribute 37440393Sbostic * and apply it to the targets if it is. Else decide if there is 37540393Sbostic * some attribute which should be applied *to* the source because 37640393Sbostic * of some special target and apply it if so. Otherwise, make the 37740393Sbostic * source be a child of the targets in the list 'targets' 37840393Sbostic * 37940393Sbostic * Results: 38040393Sbostic * None 38140393Sbostic * 38240393Sbostic * Side Effects: 38340393Sbostic * Operator bits may be added to the list of targets or to the source. 38440393Sbostic * The targets may have a new source added to their lists of children. 38540393Sbostic *--------------------------------------------------------------------- 38640393Sbostic */ 38740393Sbostic static void 38840393Sbostic ParseDoSrc (tOp, src) 38940393Sbostic int tOp; /* operator (if any) from special targets */ 39040393Sbostic char *src; /* name of the source to handle */ 39140393Sbostic { 39240393Sbostic int op; /* operator (if any) from special source */ 39340393Sbostic GNode *gn; 39440393Sbostic 39540393Sbostic op = 0; 39640393Sbostic if (*src == '.' && isupper (src[1])) { 39740393Sbostic int keywd = ParseFindKeyword(src); 39840393Sbostic if (keywd != -1) { 39940393Sbostic op = parseKeywords[keywd].op; 40040393Sbostic } 40140393Sbostic } 40240393Sbostic if (op != 0) { 40340393Sbostic Lst_ForEach (targets, ParseDoOp, (ClientData)op); 40440393Sbostic } else if (specType == Main) { 40540393Sbostic /* 40640393Sbostic * If we have noted the existence of a .MAIN, it means we need 40740393Sbostic * to add the sources of said target to the list of things 40840393Sbostic * to create. The string 'src' is likely to be free, so we 40940393Sbostic * must make a new copy of it. Note that this will only be 41040393Sbostic * invoked if the user didn't specify a target on the command 41140393Sbostic * line. This is to allow #ifmake's to succeed, or something... 41240393Sbostic */ 41340424Sbostic (void) Lst_AtEnd (create, (ClientData)strdup(src)); 41440393Sbostic /* 41540393Sbostic * Add the name to the .TARGETS variable as well, so the user cna 41640393Sbostic * employ that, if desired. 41740393Sbostic */ 41840393Sbostic Var_Append(".TARGETS", src, VAR_GLOBAL); 41940393Sbostic } else if (specType == Order) { 42040393Sbostic /* 42140393Sbostic * Create proper predecessor/successor links between the previous 42240393Sbostic * source and the current one. 42340393Sbostic */ 42440393Sbostic gn = Targ_FindNode(src, TARG_CREATE); 42540393Sbostic if (predecessor != NILGNODE) { 42640393Sbostic (void)Lst_AtEnd(predecessor->successors, (ClientData)gn); 42740393Sbostic (void)Lst_AtEnd(gn->preds, (ClientData)predecessor); 42840393Sbostic } 42940393Sbostic /* 43040393Sbostic * The current source now becomes the predecessor for the next one. 43140393Sbostic */ 43240393Sbostic predecessor = gn; 43340393Sbostic } else { 43440393Sbostic /* 43540393Sbostic * If the source is not an attribute, we need to find/create 43640393Sbostic * a node for it. After that we can apply any operator to it 43740393Sbostic * from a special target or link it to its parents, as 43840393Sbostic * appropriate. 43940393Sbostic * 44040393Sbostic * In the case of a source that was the object of a :: operator, 44140393Sbostic * the attribute is applied to all of its instances (as kept in 44240393Sbostic * the 'cohorts' list of the node) or all the cohorts are linked 44340393Sbostic * to all the targets. 44440393Sbostic */ 44540393Sbostic gn = Targ_FindNode (src, TARG_CREATE); 44640393Sbostic if (tOp) { 44740393Sbostic gn->type |= tOp; 44840393Sbostic } else { 44940393Sbostic Lst_ForEach (targets, ParseLinkSrc, (ClientData)gn); 45040393Sbostic } 45140393Sbostic if ((gn->type & OP_OPMASK) == OP_DOUBLEDEP) { 45240393Sbostic register GNode *cohort; 45340393Sbostic register LstNode ln; 45440393Sbostic 45540393Sbostic for (ln=Lst_First(gn->cohorts); ln != NILLNODE; ln = Lst_Succ(ln)){ 45640393Sbostic cohort = (GNode *)Lst_Datum(ln); 45740393Sbostic if (tOp) { 45840393Sbostic cohort->type |= tOp; 45940393Sbostic } else { 46040393Sbostic Lst_ForEach(targets, ParseLinkSrc, (ClientData)cohort); 46140393Sbostic } 46240393Sbostic } 46340393Sbostic } 46440393Sbostic } 46540393Sbostic } 46640424Sbostic 46740393Sbostic /*- 46840393Sbostic *----------------------------------------------------------------------- 46940393Sbostic * ParseFindMain -- 47040393Sbostic * Find a real target in the list and set it to be the main one. 47140393Sbostic * Called by ParseDoDependency when a main target hasn't been found 47240393Sbostic * yet. 47340393Sbostic * 47440393Sbostic * Results: 47540393Sbostic * 0 if main not found yet, 1 if it is. 47640393Sbostic * 47740393Sbostic * Side Effects: 47840393Sbostic * mainNode is changed and Targ_SetMain is called. 47940393Sbostic * 48040393Sbostic *----------------------------------------------------------------------- 48140393Sbostic */ 48240393Sbostic static int 48340393Sbostic ParseFindMain(gn) 48440393Sbostic GNode *gn; /* Node to examine */ 48540393Sbostic { 48640393Sbostic if ((gn->type & (OP_NOTMAIN|OP_USE|OP_EXEC|OP_TRANSFORM)) == 0) { 48740393Sbostic mainNode = gn; 48840393Sbostic Targ_SetMain(gn); 48940393Sbostic return (1); 49040393Sbostic } else { 49140393Sbostic return (0); 49240393Sbostic } 49340393Sbostic } 49440424Sbostic 49540393Sbostic /*- 49640393Sbostic *----------------------------------------------------------------------- 49740393Sbostic * ParseAddDir -- 49840393Sbostic * Front-end for Dir_AddDir to make sure Lst_ForEach keeps going 49940393Sbostic * 50040393Sbostic * Results: 50140393Sbostic * === 0 50240393Sbostic * 50340393Sbostic * Side Effects: 50440393Sbostic * See Dir_AddDir. 50540393Sbostic * 50640393Sbostic *----------------------------------------------------------------------- 50740393Sbostic */ 50840393Sbostic static int 50940393Sbostic ParseAddDir(path, name) 51040393Sbostic Lst path; 51140393Sbostic char *name; 51240393Sbostic { 51340393Sbostic Dir_AddDir(path, name); 51440393Sbostic return(0); 51540393Sbostic } 51640424Sbostic 51740393Sbostic /*- 51840393Sbostic *----------------------------------------------------------------------- 51940393Sbostic * ParseClearPath -- 52040393Sbostic * Front-end for Dir_ClearPath to make sure Lst_ForEach keeps going 52140393Sbostic * 52240393Sbostic * Results: 52340393Sbostic * === 0 52440393Sbostic * 52540393Sbostic * Side Effects: 52640393Sbostic * See Dir_ClearPath 52740393Sbostic * 52840393Sbostic *----------------------------------------------------------------------- 52940393Sbostic */ 53040393Sbostic static int 53140393Sbostic ParseClearPath(path) 53240393Sbostic Lst path; 53340393Sbostic { 53440393Sbostic Dir_ClearPath(path); 53540393Sbostic return(0); 53640393Sbostic } 53740424Sbostic 53840393Sbostic /*- 53940393Sbostic *--------------------------------------------------------------------- 54040393Sbostic * ParseDoDependency -- 54140393Sbostic * Parse the dependency line in line. 54240393Sbostic * 54340393Sbostic * Results: 54440393Sbostic * None 54540393Sbostic * 54640393Sbostic * Side Effects: 54740393Sbostic * The nodes of the sources are linked as children to the nodes of the 54840393Sbostic * targets. Some nodes may be created. 54940393Sbostic * 55040393Sbostic * We parse a dependency line by first extracting words from the line and 55140393Sbostic * finding nodes in the list of all targets with that name. This is done 55240393Sbostic * until a character is encountered which is an operator character. Currently 55340393Sbostic * these are only ! and :. At this point the operator is parsed and the 55440393Sbostic * pointer into the line advanced until the first source is encountered. 55540393Sbostic * The parsed operator is applied to each node in the 'targets' list, 55640393Sbostic * which is where the nodes found for the targets are kept, by means of 55740393Sbostic * the ParseDoOp function. 55840393Sbostic * The sources are read in much the same way as the targets were except 55940393Sbostic * that now they are expanded using the wildcarding scheme of the C-Shell 56040393Sbostic * and all instances of the resulting words in the list of all targets 56140393Sbostic * are found. Each of the resulting nodes is then linked to each of the 56240393Sbostic * targets as one of its children. 56340393Sbostic * Certain targets are handled specially. These are the ones detailed 56440393Sbostic * by the specType variable. 56540393Sbostic * The storing of transformation rules is also taken care of here. 56640393Sbostic * A target is recognized as a transformation rule by calling 56740393Sbostic * Suff_IsTransform. If it is a transformation rule, its node is gotten 56840393Sbostic * from the suffix module via Suff_AddTransform rather than the standard 56940393Sbostic * Targ_FindNode in the target module. 57040393Sbostic *--------------------------------------------------------------------- 57140393Sbostic */ 57240393Sbostic static void 57340393Sbostic ParseDoDependency (line) 57440393Sbostic char *line; /* the line to parse */ 57540393Sbostic { 57640393Sbostic register char *cp; /* our current position */ 57740393Sbostic register GNode *gn; /* a general purpose temporary node */ 57840393Sbostic register int op; /* the operator on the line */ 57940393Sbostic char savec; /* a place to save a character */ 58040393Sbostic Lst paths; /* List of search paths to alter when parsing 58140393Sbostic * a list of .PATH targets */ 58240393Sbostic int tOp; /* operator from special target */ 58340393Sbostic Lst sources; /* list of source names after expansion */ 58440393Sbostic Lst curTargs; /* list of target names to be found and added 58540393Sbostic * to the targets list */ 58640393Sbostic 58740393Sbostic tOp = 0; 58840393Sbostic 58940393Sbostic specType = Not; 59040393Sbostic paths = (Lst)NULL; 59140393Sbostic 59240393Sbostic curTargs = Lst_Init(FALSE); 59340393Sbostic 59440393Sbostic do { 59540393Sbostic for (cp = line; 59640393Sbostic *cp && !isspace (*cp) && 59740393Sbostic (*cp != '!') && (*cp != ':') && (*cp != '('); 59840393Sbostic cp++) 59940393Sbostic { 60040393Sbostic if (*cp == '$') { 60140393Sbostic /* 60240393Sbostic * Must be a dynamic source (would have been expanded 60340393Sbostic * otherwise), so call the Var module to parse the puppy 60440393Sbostic * so we can safely advance beyond it...There should be 60540393Sbostic * no errors in this, as they would have been discovered 60640393Sbostic * in the initial Var_Subst and we wouldn't be here. 60740393Sbostic */ 60840393Sbostic int length; 60940393Sbostic Boolean freeIt; 61040393Sbostic char *result; 61140393Sbostic 61240393Sbostic result=Var_Parse(cp, VAR_CMD, TRUE, &length, &freeIt); 61340393Sbostic 61440393Sbostic if (freeIt) { 61540393Sbostic free(result); 61640393Sbostic } 61740393Sbostic cp += length-1; 61840393Sbostic } 61940393Sbostic continue; 62040393Sbostic } 62140393Sbostic if (*cp == '(') { 62240393Sbostic /* 62340393Sbostic * Archives must be handled specially to make sure the OP_ARCHV 62440393Sbostic * flag is set in their 'type' field, for one thing, and because 62540393Sbostic * things like "archive(file1.o file2.o file3.o)" are permissible. 62640393Sbostic * Arch_ParseArchive will set 'line' to be the first non-blank 62740393Sbostic * after the archive-spec. It creates/finds nodes for the members 62840393Sbostic * and places them on the given list, returning SUCCESS if all 62940393Sbostic * went well and FAILURE if there was an error in the 63040393Sbostic * specification. On error, line should remain untouched. 63140393Sbostic */ 63240393Sbostic if (Arch_ParseArchive (&line, targets, VAR_CMD) != SUCCESS) { 63340393Sbostic Parse_Error (PARSE_FATAL, 63440393Sbostic "Error in archive specification: \"%s\"", line); 63540393Sbostic return; 63640393Sbostic } else { 63740393Sbostic continue; 63840393Sbostic } 63940393Sbostic } 64040393Sbostic savec = *cp; 64140393Sbostic 64240393Sbostic if (!*cp) { 64340393Sbostic /* 64440393Sbostic * Ending a dependency line without an operator is a Bozo 64540393Sbostic * no-no 64640393Sbostic */ 64740393Sbostic Parse_Error (PARSE_FATAL, "Need an operator"); 64840393Sbostic return; 64940393Sbostic } 65040393Sbostic *cp = '\0'; 65140393Sbostic /* 65240393Sbostic * Have a word in line. See if it's a special target and set 65340393Sbostic * specType to match it. 65440393Sbostic */ 65540393Sbostic if (*line == '.' && isupper (line[1])) { 65640393Sbostic /* 65740393Sbostic * See if the target is a special target that must have it 65840393Sbostic * or its sources handled specially. 65940393Sbostic */ 66040393Sbostic int keywd = ParseFindKeyword(line); 66140393Sbostic if (keywd != -1) { 66240393Sbostic if (specType == Path && parseKeywords[keywd].spec != Path) { 66340393Sbostic Parse_Error(PARSE_FATAL, "Mismatched special targets"); 66440393Sbostic return; 66540393Sbostic } 66640393Sbostic 66740393Sbostic specType = parseKeywords[keywd].spec; 66840393Sbostic tOp = parseKeywords[keywd].op; 66940393Sbostic 67040393Sbostic /* 67140393Sbostic * Certain special targets have special semantics: 67240393Sbostic * .PATH Have to set the dirSearchPath 67340393Sbostic * variable too 67440393Sbostic * .MAIN Its sources are only used if 67540393Sbostic * nothing has been specified to 67640393Sbostic * create. 67740393Sbostic * .DEFAULT Need to create a node to hang 67840393Sbostic * commands on, but we don't want 67940393Sbostic * it in the graph, nor do we want 68040393Sbostic * it to be the Main Target, so we 68140393Sbostic * create it, set OP_NOTMAIN and 68240393Sbostic * add it to the list, setting 68340393Sbostic * DEFAULT to the new node for 68440393Sbostic * later use. We claim the node is 68540393Sbostic * A transformation rule to make 68640393Sbostic * life easier later, when we'll 68740393Sbostic * use Make_HandleUse to actually 68840393Sbostic * apply the .DEFAULT commands. 68940393Sbostic * .BEGIN 69040393Sbostic * .END 69140393Sbostic * .INTERRUPT Are not to be considered the 69240393Sbostic * main target. 69340393Sbostic * .NOTPARALLEL Make only one target at a time. 69440393Sbostic * .SINGLESHELL Create a shell for each command. 69540393Sbostic * .ORDER Must set initial predecessor to NIL 69640393Sbostic */ 69740393Sbostic switch (specType) { 69840393Sbostic case Path: 69940393Sbostic if (paths == NULL) { 70040393Sbostic paths = Lst_Init(FALSE); 70140393Sbostic } 70240393Sbostic (void)Lst_AtEnd(paths, (ClientData)dirSearchPath); 70340393Sbostic break; 70440393Sbostic case Main: 70540393Sbostic if (!Lst_IsEmpty(create)) { 70640393Sbostic specType = Not; 70740393Sbostic } 70840393Sbostic break; 70940393Sbostic case Begin: 71040393Sbostic case End: 71140393Sbostic case Interrupt: 71240393Sbostic gn = Targ_FindNode(line, TARG_CREATE); 71340393Sbostic gn->type |= OP_NOTMAIN; 71440393Sbostic (void)Lst_AtEnd(targets, (ClientData)gn); 71540393Sbostic break; 71640393Sbostic case Default: 71740393Sbostic gn = Targ_NewGN(".DEFAULT"); 71840393Sbostic gn->type |= (OP_NOTMAIN|OP_TRANSFORM); 71940393Sbostic (void)Lst_AtEnd(targets, (ClientData)gn); 72040393Sbostic DEFAULT = gn; 72140393Sbostic break; 72240393Sbostic case NotParallel: 72340393Sbostic { 72440393Sbostic extern int maxJobs; 72540393Sbostic 72640393Sbostic maxJobs = 1; 72740393Sbostic break; 72840393Sbostic } 72940393Sbostic case SingleShell: 73040393Sbostic backwards = 1; 73140393Sbostic break; 73240393Sbostic case Order: 73340393Sbostic predecessor = NILGNODE; 73440393Sbostic break; 73540393Sbostic } 73640393Sbostic } else if (strncmp (line, ".PATH", 5) == 0) { 73740393Sbostic /* 73840393Sbostic * .PATH<suffix> has to be handled specially. 73940393Sbostic * Call on the suffix module to give us a path to 74040393Sbostic * modify. 74140393Sbostic */ 74240393Sbostic Lst path; 74340393Sbostic 74440393Sbostic specType = Path; 74540393Sbostic path = Suff_GetPath (&line[5]); 74640393Sbostic if (path == NILLST) { 74740393Sbostic Parse_Error (PARSE_FATAL, 74840393Sbostic "Suffix '%s' not defined (yet)", 74940393Sbostic &line[5]); 75040393Sbostic return; 75140393Sbostic } else { 75240393Sbostic if (paths == (Lst)NULL) { 75340393Sbostic paths = Lst_Init(FALSE); 75440393Sbostic } 75540393Sbostic (void)Lst_AtEnd(paths, (ClientData)path); 75640393Sbostic } 75740393Sbostic } 75840393Sbostic } 75940393Sbostic 76040393Sbostic /* 76140393Sbostic * Have word in line. Get or create its node and stick it at 76240393Sbostic * the end of the targets list 76340393Sbostic */ 76440393Sbostic if ((specType == Not) && (*line != '\0')) { 76540393Sbostic if (Dir_HasWildcards(line)) { 76640393Sbostic /* 76740393Sbostic * Targets are to be sought only in the current directory, 76840393Sbostic * so create an empty path for the thing. Note we need to 76940393Sbostic * use Dir_Destroy in the destruction of the path as the 77040393Sbostic * Dir module could have added a directory to the path... 77140393Sbostic */ 77240393Sbostic Lst emptyPath = Lst_Init(FALSE); 77340393Sbostic 77440393Sbostic Dir_Expand(line, emptyPath, curTargs); 77540393Sbostic 77640393Sbostic Lst_Destroy(emptyPath, Dir_Destroy); 77740393Sbostic } else { 77840393Sbostic /* 77940393Sbostic * No wildcards, but we want to avoid code duplication, 78040393Sbostic * so create a list with the word on it. 78140393Sbostic */ 78240393Sbostic (void)Lst_AtEnd(curTargs, (ClientData)line); 78340393Sbostic } 78440393Sbostic 78540393Sbostic while(!Lst_IsEmpty(curTargs)) { 78640393Sbostic char *targName = (char *)Lst_DeQueue(curTargs); 78740393Sbostic 78840393Sbostic if (!Suff_IsTransform (targName)) { 78940393Sbostic gn = Targ_FindNode (targName, TARG_CREATE); 79040393Sbostic } else { 79140393Sbostic gn = Suff_AddTransform (targName); 79240393Sbostic } 79340393Sbostic 79440393Sbostic (void)Lst_AtEnd (targets, (ClientData)gn); 79540393Sbostic } 79640393Sbostic } else if (specType == Path && *line != '.' && *line != '\0') { 79740393Sbostic Parse_Error(PARSE_WARNING, "Extra target (%s) ignored", line); 79840393Sbostic } 79940393Sbostic 80040393Sbostic *cp = savec; 80140393Sbostic /* 80240393Sbostic * If it is a special type and not .PATH, it's the only target we 80340393Sbostic * allow on this line... 80440393Sbostic */ 80540393Sbostic if (specType != Not && specType != Path) { 80640393Sbostic Boolean warn = FALSE; 80740393Sbostic 80840393Sbostic while ((*cp != '!') && (*cp != ':') && *cp) { 80940393Sbostic if (*cp != ' ' && *cp != '\t') { 81040393Sbostic warn = TRUE; 81140393Sbostic } 81240393Sbostic cp++; 81340393Sbostic } 81440393Sbostic if (warn) { 81540393Sbostic Parse_Error(PARSE_WARNING, "Extra target ignored"); 81640393Sbostic } 81740393Sbostic } else { 81840393Sbostic while (*cp && isspace (*cp)) { 81940393Sbostic cp++; 82040393Sbostic } 82140393Sbostic } 82240393Sbostic line = cp; 82340393Sbostic } while ((*line != '!') && (*line != ':') && *line); 82440393Sbostic 82540393Sbostic /* 82640393Sbostic * Don't need the list of target names anymore... 82740393Sbostic */ 82840393Sbostic Lst_Destroy(curTargs, NOFREE); 82940393Sbostic 83040393Sbostic if (!Lst_IsEmpty(targets)) { 83140393Sbostic switch(specType) { 83240393Sbostic default: 83340393Sbostic Parse_Error(PARSE_WARNING, "Special and mundane targets don't mix. Mundane ones ignored"); 83440393Sbostic break; 83540393Sbostic case Default: 83640393Sbostic case Begin: 83740393Sbostic case End: 83840393Sbostic case Interrupt: 83940393Sbostic /* 84040393Sbostic * These four create nodes on which to hang commands, so 84140393Sbostic * targets shouldn't be empty... 84240393Sbostic */ 84340393Sbostic case Not: 84440393Sbostic /* 84540393Sbostic * Nothing special here -- targets can be empty if it wants. 84640393Sbostic */ 84740393Sbostic break; 84840393Sbostic } 84940393Sbostic } 85040393Sbostic 85140393Sbostic /* 85240393Sbostic * Have now parsed all the target names. Must parse the operator next. The 85340393Sbostic * result is left in op . 85440393Sbostic */ 85540393Sbostic if (*cp == '!') { 85640393Sbostic op = OP_FORCE; 85740393Sbostic } else if (*cp == ':') { 85840393Sbostic if (cp[1] == ':') { 85940393Sbostic op = OP_DOUBLEDEP; 86040393Sbostic cp++; 86140393Sbostic } else { 86240393Sbostic op = OP_DEPENDS; 86340393Sbostic } 86440393Sbostic } else { 86540393Sbostic Parse_Error (PARSE_FATAL, "Missing dependency operator"); 86640393Sbostic return; 86740393Sbostic } 86840393Sbostic 86940393Sbostic cp++; /* Advance beyond operator */ 87040393Sbostic 87140393Sbostic Lst_ForEach (targets, ParseDoOp, (ClientData)op); 87240393Sbostic 87340393Sbostic /* 87440393Sbostic * Get to the first source 87540393Sbostic */ 87640393Sbostic while (*cp && isspace (*cp)) { 87740393Sbostic cp++; 87840393Sbostic } 87940393Sbostic line = cp; 88040393Sbostic 88140393Sbostic /* 88240393Sbostic * Several special targets take different actions if present with no 88340393Sbostic * sources: 88440393Sbostic * a .SUFFIXES line with no sources clears out all old suffixes 88540393Sbostic * a .PRECIOUS line makes all targets precious 88640393Sbostic * a .IGNORE line ignores errors for all targets 88740393Sbostic * a .SILENT line creates silence when making all targets 88840393Sbostic * a .PATH removes all directories from the search path(s). 88940393Sbostic */ 89040393Sbostic if (!*line) { 89140393Sbostic switch (specType) { 89240393Sbostic case Suffixes: 89340393Sbostic Suff_ClearSuffixes (); 89440393Sbostic break; 89540393Sbostic case Precious: 89640393Sbostic allPrecious = TRUE; 89740393Sbostic break; 89840393Sbostic case Ignore: 89940393Sbostic ignoreErrors = TRUE; 90040393Sbostic break; 90140393Sbostic case Silent: 90240393Sbostic beSilent = TRUE; 90340393Sbostic break; 90440393Sbostic case Path: 90540393Sbostic Lst_ForEach(paths, ParseClearPath, (ClientData)NULL); 90640393Sbostic break; 90740393Sbostic } 90840393Sbostic } else if (specType == MFlags) { 90940393Sbostic /* 91040393Sbostic * Call on functions in main.c to deal with these arguments and 91140393Sbostic * set the initial character to a null-character so the loop to 91240393Sbostic * get sources won't get anything 91340393Sbostic */ 91440393Sbostic Main_ParseArgLine (line); 91540393Sbostic *line = '\0'; 91640393Sbostic } else if (specType == Shell) { 91740393Sbostic if (Job_ParseShell (line) != SUCCESS) { 91840393Sbostic Parse_Error (PARSE_FATAL, "improper shell specification"); 91940393Sbostic return; 92040393Sbostic } 92140393Sbostic *line = '\0'; 92240393Sbostic } else if ((specType == NotParallel) || (specType == SingleShell)) { 92340393Sbostic *line = '\0'; 92440393Sbostic } 92540393Sbostic 92640393Sbostic /* 92740393Sbostic * NOW GO FOR THE SOURCES 92840393Sbostic */ 92940393Sbostic if ((specType == Suffixes) || (specType == Path) || 93040393Sbostic (specType == Includes) || (specType == Libs) || 931*40439Sbostic (specType == Null)) 93240393Sbostic { 93340393Sbostic while (*line) { 93440393Sbostic /* 93540393Sbostic * If the target was one that doesn't take files as its sources 93640393Sbostic * but takes something like suffixes, we take each 93740393Sbostic * space-separated word on the line as a something and deal 93840393Sbostic * with it accordingly. 93940393Sbostic * 94040393Sbostic * If the target was .SUFFIXES, we take each source as a 94140393Sbostic * suffix and add it to the list of suffixes maintained by the 94240393Sbostic * Suff module. 94340393Sbostic * 94440393Sbostic * If the target was a .PATH, we add the source as a directory 94540393Sbostic * to search on the search path. 94640393Sbostic * 94740393Sbostic * If it was .INCLUDES, the source is taken to be the suffix of 94840393Sbostic * files which will be #included and whose search path should 94940393Sbostic * be present in the .INCLUDES variable. 95040393Sbostic * 95140393Sbostic * If it was .LIBS, the source is taken to be the suffix of 95240393Sbostic * files which are considered libraries and whose search path 95340393Sbostic * should be present in the .LIBS variable. 95440393Sbostic * 95540393Sbostic * If it was .NULL, the source is the suffix to use when a file 95640393Sbostic * has no valid suffix. 95740393Sbostic */ 95840393Sbostic char savec; 95940393Sbostic while (*cp && !isspace (*cp)) { 96040393Sbostic cp++; 96140393Sbostic } 96240393Sbostic savec = *cp; 96340393Sbostic *cp = '\0'; 96440393Sbostic switch (specType) { 96540393Sbostic case Suffixes: 96640393Sbostic Suff_AddSuffix (line); 96740393Sbostic break; 96840393Sbostic case Path: 96940393Sbostic Lst_ForEach(paths, ParseAddDir, (ClientData)line); 97040393Sbostic break; 97140393Sbostic case Includes: 97240393Sbostic Suff_AddInclude (line); 97340393Sbostic break; 97440393Sbostic case Libs: 97540393Sbostic Suff_AddLib (line); 97640393Sbostic break; 97740393Sbostic case Null: 97840393Sbostic Suff_SetNull (line); 97940393Sbostic break; 98040393Sbostic } 98140393Sbostic *cp = savec; 98240393Sbostic if (savec != '\0') { 98340393Sbostic cp++; 98440393Sbostic } 98540393Sbostic while (*cp && isspace (*cp)) { 98640393Sbostic cp++; 98740393Sbostic } 98840393Sbostic line = cp; 98940393Sbostic } 99040393Sbostic if (paths) { 99140393Sbostic Lst_Destroy(paths, NOFREE); 99240393Sbostic } 99340393Sbostic } else { 99440393Sbostic while (*line) { 99540393Sbostic /* 99640393Sbostic * The targets take real sources, so we must beware of archive 99740393Sbostic * specifications (i.e. things with left parentheses in them) 99840393Sbostic * and handle them accordingly. 99940393Sbostic */ 100040393Sbostic while (*cp && !isspace (*cp)) { 100140393Sbostic if ((*cp == '(') && (cp > line) && (cp[-1] != '$')) { 100240393Sbostic /* 100340393Sbostic * Only stop for a left parenthesis if it isn't at the 100440393Sbostic * start of a word (that'll be for variable changes 100540393Sbostic * later) and isn't preceded by a dollar sign (a dynamic 100640393Sbostic * source). 100740393Sbostic */ 100840393Sbostic break; 100940393Sbostic } else { 101040393Sbostic cp++; 101140393Sbostic } 101240393Sbostic } 101340393Sbostic 101440393Sbostic if (*cp == '(') { 101540393Sbostic GNode *gn; 101640393Sbostic 101740393Sbostic sources = Lst_Init (FALSE); 101840393Sbostic if (Arch_ParseArchive (&line, sources, VAR_CMD) != SUCCESS) { 101940393Sbostic Parse_Error (PARSE_FATAL, 102040393Sbostic "Error in source archive spec \"%s\"", line); 102140393Sbostic return; 102240393Sbostic } 102340393Sbostic 102440393Sbostic while (!Lst_IsEmpty (sources)) { 102540393Sbostic gn = (GNode *) Lst_DeQueue (sources); 102640393Sbostic ParseDoSrc (tOp, gn->name); 102740393Sbostic } 102840393Sbostic Lst_Destroy (sources, NOFREE); 102940393Sbostic cp = line; 103040393Sbostic } else { 103140393Sbostic if (*cp) { 103240393Sbostic *cp = '\0'; 103340393Sbostic cp += 1; 103440393Sbostic } 103540393Sbostic 103640393Sbostic ParseDoSrc (tOp, line); 103740393Sbostic } 103840393Sbostic while (*cp && isspace (*cp)) { 103940393Sbostic cp++; 104040393Sbostic } 104140393Sbostic line = cp; 104240393Sbostic } 104340393Sbostic } 104440393Sbostic 104540393Sbostic if (mainNode == NILGNODE) { 104640393Sbostic /* 104740393Sbostic * If we have yet to decide on a main target to make, in the 104840393Sbostic * absence of any user input, we want the first target on 104940393Sbostic * the first dependency line that is actually a real target 105040393Sbostic * (i.e. isn't a .USE or .EXEC rule) to be made. 105140393Sbostic */ 105240393Sbostic Lst_ForEach (targets, ParseFindMain, (ClientData)0); 105340393Sbostic } 105440393Sbostic 105540393Sbostic } 105640424Sbostic 105740393Sbostic /*- 105840393Sbostic *--------------------------------------------------------------------- 105940393Sbostic * Parse_IsVar -- 106040393Sbostic * Return TRUE if the passed line is a variable assignment. A variable 106140393Sbostic * assignment consists of a single word followed by optional whitespace 106240393Sbostic * followed by either a += or an = operator. 106340393Sbostic * This function is used both by the Parse_File function and main when 106440393Sbostic * parsing the command-line arguments. 106540393Sbostic * 106640393Sbostic * Results: 106740393Sbostic * TRUE if it is. FALSE if it ain't 106840393Sbostic * 106940393Sbostic * Side Effects: 107040393Sbostic * none 107140393Sbostic *--------------------------------------------------------------------- 107240393Sbostic */ 107340393Sbostic Boolean 107440393Sbostic Parse_IsVar (line) 107540393Sbostic register char *line; /* the line to check */ 107640393Sbostic { 107740393Sbostic register Boolean wasSpace = FALSE; /* set TRUE if found a space */ 107840393Sbostic register Boolean haveName = FALSE; /* Set TRUE if have a variable name */ 107940393Sbostic 108040393Sbostic /* 108140393Sbostic * Skip to variable name 108240393Sbostic */ 108340393Sbostic while ((*line == ' ') || (*line == '\t')) { 108440393Sbostic line++; 108540393Sbostic } 108640393Sbostic 108740393Sbostic while (*line != '=') { 108840393Sbostic if (*line == '\0') { 108940393Sbostic /* 109040393Sbostic * end-of-line -- can't be a variable assignment. 109140393Sbostic */ 109240393Sbostic return (FALSE); 109340393Sbostic } else if ((*line == ' ') || (*line == '\t')) { 109440393Sbostic /* 109540393Sbostic * there can be as much white space as desired so long as there is 109640393Sbostic * only one word before the operator 109740393Sbostic */ 109840393Sbostic wasSpace = TRUE; 109940393Sbostic } else if (wasSpace && haveName) { 110040393Sbostic /* 110140393Sbostic * Stop when an = operator is found. 110240393Sbostic */ 110340393Sbostic if ((*line == '+') || (*line == ':') || (*line == '?') || 110440393Sbostic (*line == '!')) { 110540393Sbostic break; 110640393Sbostic } 110740393Sbostic 110840393Sbostic /* 110940393Sbostic * This is the start of another word, so not assignment. 111040393Sbostic */ 111140393Sbostic return (FALSE); 111240393Sbostic } else { 111340393Sbostic haveName = TRUE; 111440393Sbostic wasSpace = FALSE; 111540393Sbostic } 111640393Sbostic line++; 111740393Sbostic } 111840393Sbostic 111940393Sbostic /* 112040393Sbostic * A final check: if we stopped on a +, ?, ! or :, the next character must 112140393Sbostic * be an = or it ain't a valid assignment 112240393Sbostic */ 112340393Sbostic if (((*line == '+') || 112440393Sbostic (*line == '?') || 112540393Sbostic (*line == ':') || 112640393Sbostic (*line == '!')) && 112740393Sbostic (line[1] != '=')) 112840393Sbostic { 112940393Sbostic return (FALSE); 113040393Sbostic } else { 113140393Sbostic return (haveName); 113240393Sbostic } 113340393Sbostic } 113440424Sbostic 113540393Sbostic /*- 113640393Sbostic *--------------------------------------------------------------------- 113740393Sbostic * Parse_DoVar -- 113840393Sbostic * Take the variable assignment in the passed line and do it in the 113940393Sbostic * global context. 114040393Sbostic * 114140393Sbostic * Note: There is a lexical ambiguity with assignment modifier characters 114240393Sbostic * in variable names. This routine interprets the character before the = 114340393Sbostic * as a modifier. Therefore, an assignment like 114440393Sbostic * C++=/usr/bin/CC 114540393Sbostic * is interpreted as "C+ +=" instead of "C++ =". 114640393Sbostic * 114740393Sbostic * Results: 114840393Sbostic * none 114940393Sbostic * 115040393Sbostic * Side Effects: 115140393Sbostic * the variable structure of the given variable name is altered in the 115240393Sbostic * global context. 115340393Sbostic *--------------------------------------------------------------------- 115440393Sbostic */ 115540393Sbostic void 115640393Sbostic Parse_DoVar (line, ctxt) 115740393Sbostic char *line; /* a line guaranteed to be a variable 115840393Sbostic * assignment. This reduces error checks */ 115940393Sbostic GNode *ctxt; /* Context in which to do the assignment */ 116040393Sbostic { 116140393Sbostic register char *cp; /* pointer into line */ 116240393Sbostic enum { 116340393Sbostic VAR_SUBST, VAR_APPEND, VAR_SHELL, VAR_NORMAL 116440393Sbostic } type; /* Type of assignment */ 116540393Sbostic char *opc; /* ptr to operator character to 116640393Sbostic * null-terminate the variable name */ 116740393Sbostic 116840393Sbostic /* 116940393Sbostic * Skip to variable name 117040393Sbostic */ 117140393Sbostic while ((*line == ' ') || (*line == '\t')) { 117240393Sbostic line++; 117340393Sbostic } 117440393Sbostic 117540393Sbostic /* 117640393Sbostic * Skip to operator character, nulling out whitespace as we go 117740393Sbostic */ 117840393Sbostic for (cp = line + 1; *cp != '='; cp++) { 117940393Sbostic if (isspace (*cp)) { 118040393Sbostic *cp = '\0'; 118140393Sbostic } 118240393Sbostic } 118340393Sbostic opc = cp-1; /* operator is the previous character */ 118440393Sbostic *cp++ = '\0'; /* nuke the = */ 118540393Sbostic 118640393Sbostic /* 118740393Sbostic * Check operator type 118840393Sbostic */ 118940393Sbostic switch (*opc) { 119040393Sbostic case '+': 119140393Sbostic type = VAR_APPEND; 119240393Sbostic *opc = '\0'; 119340393Sbostic break; 119440393Sbostic 119540393Sbostic case '?': 119640393Sbostic /* 119740393Sbostic * If the variable already has a value, we don't do anything. 119840393Sbostic */ 119940393Sbostic *opc = '\0'; 120040393Sbostic if (Var_Exists(line, ctxt)) { 120140393Sbostic return; 120240393Sbostic } else { 120340393Sbostic type = VAR_NORMAL; 120440393Sbostic } 120540393Sbostic break; 120640393Sbostic 120740393Sbostic case ':': 120840393Sbostic type = VAR_SUBST; 120940393Sbostic *opc = '\0'; 121040393Sbostic break; 121140393Sbostic 121240393Sbostic case '!': 121340393Sbostic type = VAR_SHELL; 121440393Sbostic *opc = '\0'; 121540393Sbostic break; 121640393Sbostic 121740393Sbostic default: 121840393Sbostic type = VAR_NORMAL; 121940393Sbostic break; 122040393Sbostic } 122140393Sbostic 122240393Sbostic while (isspace (*cp)) { 122340393Sbostic cp++; 122440393Sbostic } 122540393Sbostic 122640393Sbostic if (type == VAR_APPEND) { 122740393Sbostic Var_Append (line, cp, ctxt); 122840393Sbostic } else if (type == VAR_SUBST) { 122940393Sbostic /* 123040393Sbostic * Allow variables in the old value to be undefined, but leave their 123140393Sbostic * invocation alone -- this is done by forcing oldVars to be false. 123240393Sbostic * XXX: This can cause recursive variables, but that's not hard to do, 123340393Sbostic * and this allows someone to do something like 123440393Sbostic * 123540393Sbostic * CFLAGS = $(.INCLUDES) 123640393Sbostic * CFLAGS := -I.. $(CFLAGS) 123740393Sbostic * 123840393Sbostic * And not get an error. 123940393Sbostic */ 124040393Sbostic Boolean oldOldVars = oldVars; 124140393Sbostic 124240393Sbostic oldVars = FALSE; 124340393Sbostic cp = Var_Subst(cp, ctxt, FALSE); 124440393Sbostic oldVars = oldOldVars; 124540393Sbostic 124640393Sbostic Var_Set(line, cp, ctxt); 124740393Sbostic free(cp); 124840393Sbostic } else if (type == VAR_SHELL) { 124940393Sbostic char result[BUFSIZ]; /* Result of command */ 125040393Sbostic char *args[4]; /* Args for invoking the shell */ 125140393Sbostic int fds[2]; /* Pipe streams */ 125240393Sbostic int cpid; /* Child PID */ 125340393Sbostic int pid; /* PID from wait() */ 125440393Sbostic Boolean freeCmd; /* TRUE if the command needs to be freed, i.e. 125540393Sbostic * if any variable expansion was performed */ 125640393Sbostic 125740393Sbostic /* 125840393Sbostic * Set up arguments for shell 125940393Sbostic */ 126040393Sbostic args[0] = "sh"; 126140393Sbostic args[1] = "-c"; 126240393Sbostic if (index(cp, '$') != (char *)NULL) { 126340393Sbostic /* 126440393Sbostic * There's a dollar sign in the command, so perform variable 126540393Sbostic * expansion on the whole thing. The resulting string will need 126640393Sbostic * freeing when we're done, so set freeCmd to TRUE. 126740393Sbostic */ 126840393Sbostic args[2] = Var_Subst(cp, VAR_CMD, TRUE); 126940393Sbostic freeCmd = TRUE; 127040393Sbostic } else { 127140393Sbostic args[2] = cp; 127240393Sbostic freeCmd = FALSE; 127340393Sbostic } 127440393Sbostic args[3] = (char *)NULL; 127540393Sbostic 127640393Sbostic /* 127740393Sbostic * Open a pipe for fetching its output 127840393Sbostic */ 127940393Sbostic pipe(fds); 128040393Sbostic 128140393Sbostic /* 128240393Sbostic * Fork 128340393Sbostic */ 128440393Sbostic cpid = vfork(); 128540393Sbostic if (cpid == 0) { 128640393Sbostic /* 128740393Sbostic * Close input side of pipe 128840393Sbostic */ 128940393Sbostic close(fds[0]); 129040393Sbostic 129140393Sbostic /* 129240393Sbostic * Duplicate the output stream to the shell's output, then 129340393Sbostic * shut the extra thing down. Note we don't fetch the error 129440393Sbostic * stream...why not? Why? 129540393Sbostic */ 129640393Sbostic dup2(fds[1], 1); 129740393Sbostic close(fds[1]); 129840393Sbostic 129940393Sbostic execv("/bin/sh", args); 130040393Sbostic _exit(1); 130140393Sbostic } else if (cpid < 0) { 130240393Sbostic /* 130340393Sbostic * Couldn't fork -- tell the user and make the variable null 130440393Sbostic */ 130540393Sbostic Parse_Error(PARSE_WARNING, "Couldn't exec \"%s\"", cp); 130640393Sbostic Var_Set(line, "", ctxt); 130740393Sbostic } else { 130840393Sbostic int status; 130940393Sbostic int cc; 131040393Sbostic 131140393Sbostic /* 131240393Sbostic * No need for the writing half 131340393Sbostic */ 131440393Sbostic close(fds[1]); 131540393Sbostic 131640393Sbostic /* 131740393Sbostic * Wait for the process to exit. 131840393Sbostic * 131940393Sbostic * XXX: If the child writes more than a pipe's worth, we will 132040393Sbostic * deadlock. 132140393Sbostic */ 132240393Sbostic while(((pid = wait(&status)) != cpid) && (pid >= 0)) { 132340393Sbostic ; 132440393Sbostic } 132540393Sbostic 132640393Sbostic /* 132740393Sbostic * Read all the characters the child wrote. 132840393Sbostic */ 132940393Sbostic cc = read(fds[0], result, sizeof(result)); 133040393Sbostic 133140393Sbostic if (cc < 0) { 133240393Sbostic /* 133340393Sbostic * Couldn't read the child's output -- tell the user and 133440393Sbostic * set the variable to null 133540393Sbostic */ 133640393Sbostic Parse_Error(PARSE_WARNING, "Couldn't read shell's output"); 133740393Sbostic cc = 0; 133840393Sbostic } 133940393Sbostic 134040393Sbostic if (status) { 134140393Sbostic /* 134240393Sbostic * Child returned an error -- tell the user but still use 134340393Sbostic * the result. 134440393Sbostic */ 134540393Sbostic Parse_Error(PARSE_WARNING, "\"%s\" returned non-zero", cp); 134640393Sbostic } 134740393Sbostic /* 134840393Sbostic * Null-terminate the result, convert newlines to spaces and 134940393Sbostic * install it in the variable. 135040393Sbostic */ 135140393Sbostic result[cc] = '\0'; 135240393Sbostic cp = &result[cc] - 1; 135340393Sbostic 135440393Sbostic if (*cp == '\n') { 135540393Sbostic /* 135640393Sbostic * A final newline is just stripped 135740393Sbostic */ 135840393Sbostic *cp-- = '\0'; 135940393Sbostic } 136040393Sbostic while (cp >= result) { 136140393Sbostic if (*cp == '\n') { 136240393Sbostic *cp = ' '; 136340393Sbostic } 136440393Sbostic cp--; 136540393Sbostic } 136640393Sbostic Var_Set(line, result, ctxt); 136740393Sbostic 136840393Sbostic /* 136940393Sbostic * Close the input side of the pipe. 137040393Sbostic */ 137140393Sbostic close(fds[0]); 137240393Sbostic } 137340393Sbostic if (freeCmd) { 137440393Sbostic free(args[2]); 137540393Sbostic } 137640393Sbostic } else { 137740393Sbostic /* 137840393Sbostic * Normal assignment -- just do it. 137940393Sbostic */ 138040393Sbostic Var_Set (line, cp, ctxt); 138140393Sbostic } 138240393Sbostic } 138340424Sbostic 138440393Sbostic /*- 138540393Sbostic *--------------------------------------------------------------------- 138640393Sbostic * ParseAddCmd -- 138740393Sbostic * Lst_ForEach function to add a command line to all targets 138840393Sbostic * 138940393Sbostic * Results: 139040393Sbostic * Always 0 139140393Sbostic * 139240393Sbostic * Side Effects: 139340393Sbostic * A new element is added to the commands list of the node. 139440393Sbostic *--------------------------------------------------------------------- 139540393Sbostic */ 139640393Sbostic static int 139740393Sbostic ParseAddCmd (gn, cmd) 139840393Sbostic GNode *gn; /* the node to which the command is to be 139940393Sbostic * added */ 140040393Sbostic char *cmd; /* the command to add */ 140140393Sbostic { 140240393Sbostic if (gn->type & OP_HAS_COMMANDS) { 140340393Sbostic Parse_Error(PARSE_WARNING, "Extra command line for \"%s\" ignored", 140440393Sbostic gn->name); 140540393Sbostic } else { 140640393Sbostic (void)Lst_AtEnd (gn->commands, (ClientData)cmd); 140740393Sbostic } 140840393Sbostic 140940393Sbostic return (0); 141040393Sbostic } 141140424Sbostic 141240393Sbostic /*- 141340393Sbostic *----------------------------------------------------------------------- 141440393Sbostic * ParseHasCommands -- 141540393Sbostic * Callback procedure for Parse_File when destroying the list of 141640393Sbostic * targets on the last dependency line. Marks a target as already 141740393Sbostic * having commands if it does, to keep from having shell commands 141840393Sbostic * on multiple dependency lines. 141940393Sbostic * 142040393Sbostic * Results: 142140393Sbostic * Always 0. 142240393Sbostic * 142340393Sbostic * Side Effects: 142440393Sbostic * OP_HAS_COMMANDS may be set for the target. 142540393Sbostic * 142640393Sbostic *----------------------------------------------------------------------- 142740393Sbostic */ 142840393Sbostic static int 142940393Sbostic ParseHasCommands(gn) 143040393Sbostic GNode *gn; /* Node to examine */ 143140393Sbostic { 143240393Sbostic if (!Lst_IsEmpty(gn->commands)) { 143340393Sbostic gn->type |= OP_HAS_COMMANDS; 143440393Sbostic } 143540393Sbostic return(0); 143640393Sbostic } 143740424Sbostic 143840393Sbostic /*- 143940393Sbostic *----------------------------------------------------------------------- 144040393Sbostic * Parse_AddIncludeDir -- 144140393Sbostic * Add a directory to the path searched for included makefiles 144240393Sbostic * bracketed by double-quotes. Used by functions in main.c 144340393Sbostic * 144440393Sbostic * Results: 144540393Sbostic * None. 144640393Sbostic * 144740393Sbostic * Side Effects: 144840393Sbostic * The directory is appended to the list. 144940393Sbostic * 145040393Sbostic *----------------------------------------------------------------------- 145140393Sbostic */ 145240393Sbostic void 145340393Sbostic Parse_AddIncludeDir (dir) 145440393Sbostic char *dir; /* The name of the directory to add */ 145540393Sbostic { 145640393Sbostic Dir_AddDir (parseIncPath, dir); 145740393Sbostic } 145840424Sbostic 145940393Sbostic /*- 146040393Sbostic *--------------------------------------------------------------------- 146140393Sbostic * ParseDoInclude -- 146240393Sbostic * Push to another file. 146340393Sbostic * 146440393Sbostic * The input is the line minus the #include. A file spec is a string 146540393Sbostic * enclosed in <> or "". The former is looked for only in sysIncPath. 146640393Sbostic * The latter in . and the directories specified by -I command line 146740393Sbostic * options 146840393Sbostic * 146940393Sbostic * Results: 147040393Sbostic * None 147140393Sbostic * 147240393Sbostic * Side Effects: 147340393Sbostic * A structure is added to the includes Lst and readProc, lineno, 147440393Sbostic * fname and curFILE are altered for the new file 147540393Sbostic *--------------------------------------------------------------------- 147640393Sbostic */ 147740393Sbostic static void 147840393Sbostic ParseDoInclude (file) 147940393Sbostic char *file; /* file specification */ 148040393Sbostic { 148140393Sbostic char *fullname; /* full pathname of file */ 148240393Sbostic IFile *oldFile; /* state associated with current file */ 148340393Sbostic Lst path; /* the path to use to find the file */ 148440393Sbostic char endc; /* the character which ends the file spec */ 148540393Sbostic char *cp; /* current position in file spec */ 148640393Sbostic Boolean isSystem; /* TRUE if makefile is a system makefile */ 148740393Sbostic 148840393Sbostic /* 148940393Sbostic * Skip to delimiter character so we know where to look 149040393Sbostic */ 149140393Sbostic while ((*file == ' ') || (*file == '\t')) { 149240393Sbostic file++; 149340393Sbostic } 149440393Sbostic 149540393Sbostic if ((*file != '"') && (*file != '<')) { 149640393Sbostic /* 149740393Sbostic * XXX: Should give some sort of error message, I suppose, but because 149840393Sbostic * # is used for both comments and directives, we can't be sure if 149940393Sbostic * the thing might not just be a comment, so we just return... 150040393Sbostic */ 150140393Sbostic return; 150240393Sbostic } 150340393Sbostic 150440393Sbostic /* 150540393Sbostic * Set the search path on which to find the include file based on the 150640393Sbostic * characters which bracket its name. Angle-brackets imply it's 150740393Sbostic * a system Makefile while double-quotes imply it's a user makefile 150840393Sbostic */ 150940393Sbostic if (*file == '<') { 151040393Sbostic isSystem = TRUE; 151140393Sbostic endc = '>'; 151240393Sbostic } else { 151340393Sbostic isSystem = FALSE; 151440393Sbostic endc = '"'; 151540393Sbostic } 151640393Sbostic 151740393Sbostic /* 151840393Sbostic * Skip to matching delimiter 151940393Sbostic */ 152040393Sbostic for (cp = ++file; *cp && *cp != endc; cp++) { 152140393Sbostic continue; 152240393Sbostic } 152340393Sbostic 152440393Sbostic if (*cp != endc) { 152540393Sbostic Parse_Error (PARSE_FATAL, 152640435Sbostic "Unclosed .include filename. '%c' expected", endc); 152740393Sbostic return; 152840393Sbostic } 152940393Sbostic *cp = '\0'; 153040393Sbostic 153140393Sbostic /* 153240393Sbostic * Substitute for any variables in the file name before trying to 153340393Sbostic * find the thing. 153440393Sbostic */ 153540393Sbostic file = Var_Subst (file, VAR_CMD, FALSE); 153640393Sbostic 153740393Sbostic /* 153840393Sbostic * Now we know the file's name and its search path, we attempt to 153940393Sbostic * find the durn thing. A return of NULL indicates the file don't 154040393Sbostic * exist. 154140393Sbostic */ 154240393Sbostic if (!isSystem) { 154340393Sbostic /* 154440393Sbostic * Include files contained in double-quotes are first searched for 154540393Sbostic * relative to the including file's location. We don't want to 154640393Sbostic * cd there, of course, so we just tack on the old file's 154740393Sbostic * leading path components and call Dir_FindFile to see if 154840393Sbostic * we can locate the beast. 154940393Sbostic */ 155040393Sbostic char *prefEnd; 155140393Sbostic 155240393Sbostic prefEnd = rindex (fname, '/'); 155340393Sbostic if (prefEnd != (char *)NULL) { 155440393Sbostic char *newName; 155540393Sbostic 155640393Sbostic *prefEnd = '\0'; 155740393Sbostic newName = Str_Concat (fname, file, STR_ADDSLASH); 155840393Sbostic fullname = Dir_FindFile (newName, parseIncPath); 155940393Sbostic if (fullname == (char *)NULL) { 156040393Sbostic fullname = Dir_FindFile(newName, dirSearchPath); 156140393Sbostic } 156240393Sbostic free (newName); 156340393Sbostic *prefEnd = '/'; 156440393Sbostic } else { 156540393Sbostic fullname = (char *)NULL; 156640393Sbostic } 156740393Sbostic } else { 156840393Sbostic fullname = (char *)NULL; 156940393Sbostic } 157040393Sbostic 157140393Sbostic if (fullname == (char *)NULL) { 157240393Sbostic /* 157340393Sbostic * System makefile or makefile wasn't found in same directory as 157440393Sbostic * included makefile. Search for it first on the -I search path, 157540393Sbostic * then on the .PATH search path, if not found in a -I directory. 157640393Sbostic * XXX: Suffix specific? 157740393Sbostic */ 157840393Sbostic fullname = Dir_FindFile (file, parseIncPath); 157940393Sbostic if (fullname == (char *)NULL) { 158040393Sbostic fullname = Dir_FindFile(file, dirSearchPath); 158140393Sbostic } 158240393Sbostic } 158340393Sbostic 158440393Sbostic if (fullname == (char *)NULL) { 158540393Sbostic /* 158640393Sbostic * Still haven't found the makefile. Look for it on the system 158740393Sbostic * path as a last resort. 158840393Sbostic */ 158940393Sbostic fullname = Dir_FindFile(file, sysIncPath); 159040393Sbostic } 159140393Sbostic 159240393Sbostic if (fullname == (char *) NULL) { 159340393Sbostic *cp = endc; 159440393Sbostic Parse_Error (PARSE_FATAL, "Could not find %s", file); 159540393Sbostic return; 159640393Sbostic } 159740393Sbostic 159840393Sbostic /* 159940393Sbostic * Once we find the absolute path to the file, we get to save all the 160040393Sbostic * state from the current file before we can start reading this 160140393Sbostic * include file. The state is stored in an IFile structure which 160240393Sbostic * is placed on a list with other IFile structures. The list makes 160340393Sbostic * a very nice stack to track how we got here... 160440393Sbostic */ 160540393Sbostic oldFile = (IFile *) malloc (sizeof (IFile)); 160640393Sbostic oldFile->fname = fname; 160740393Sbostic 160840393Sbostic oldFile->F = curFILE; 160940393Sbostic oldFile->lineno = lineno; 161040393Sbostic 161140393Sbostic (void) Lst_AtFront (includes, (ClientData)oldFile); 161240393Sbostic 161340393Sbostic /* 161440393Sbostic * Once the previous state has been saved, we can get down to reading 161540393Sbostic * the new file. We set up the name of the file to be the absolute 161640393Sbostic * name of the include file so error messages refer to the right 161740393Sbostic * place. Naturally enough, we start reading at line number 0. 161840393Sbostic */ 161940393Sbostic fname = fullname; 162040393Sbostic lineno = 0; 162140393Sbostic 162240393Sbostic curFILE = fopen (fullname, "r"); 162340393Sbostic if (curFILE == (FILE * ) NULL) { 162440393Sbostic Parse_Error (PARSE_FATAL, "Cannot open %s", fullname); 162540393Sbostic /* 162640393Sbostic * Pop to previous file 162740393Sbostic */ 162840393Sbostic (void) ParseEOF(); 162940393Sbostic } 163040393Sbostic } 163140424Sbostic 163240393Sbostic /*- 163340393Sbostic *--------------------------------------------------------------------- 163440393Sbostic * ParseEOF -- 163540393Sbostic * Called when EOF is reached in the current file. If we were reading 163640393Sbostic * an include file, the includes stack is popped and things set up 163740393Sbostic * to go back to reading the previous file at the previous location. 163840393Sbostic * 163940393Sbostic * Results: 164040393Sbostic * CONTINUE if there's more to do. DONE if not. 164140393Sbostic * 164240393Sbostic * Side Effects: 164340393Sbostic * The old curFILE, is closed. The includes list is shortened. 164440393Sbostic * lineno, curFILE, and fname are changed if CONTINUE is returned. 164540393Sbostic *--------------------------------------------------------------------- 164640393Sbostic */ 164740393Sbostic static int 164840393Sbostic ParseEOF () 164940393Sbostic { 165040393Sbostic IFile *ifile; /* the state on the top of the includes stack */ 165140393Sbostic 165240393Sbostic if (Lst_IsEmpty (includes)) { 165340393Sbostic return (DONE); 165440393Sbostic } 165540393Sbostic 165640393Sbostic ifile = (IFile *) Lst_DeQueue (includes); 165740393Sbostic free (fname); 165840393Sbostic fname = ifile->fname; 165940393Sbostic lineno = ifile->lineno; 166040393Sbostic fclose (curFILE); 166140393Sbostic curFILE = ifile->F; 166240393Sbostic free ((Address)ifile); 166340393Sbostic return (CONTINUE); 166440393Sbostic } 166540424Sbostic 166640393Sbostic /*- 166740393Sbostic *--------------------------------------------------------------------- 166840393Sbostic * ParseReadc -- 166940393Sbostic * Read a character from the current file and update the line number 167040393Sbostic * counter as necessary 167140393Sbostic * 167240393Sbostic * Results: 167340393Sbostic * The character that was read 167440393Sbostic * 167540393Sbostic * Side Effects: 167640393Sbostic * The lineno counter is incremented if the character is a newline 167740393Sbostic *--------------------------------------------------------------------- 167840393Sbostic */ 167940393Sbostic #ifdef notdef 168040393Sbostic static int parseReadChar; 168140393Sbostic 168240393Sbostic #define ParseReadc() (((parseReadChar = getc(curFILE)) == '\n') ? \ 168340393Sbostic (lineno++, '\n') : parseReadChar) 168440393Sbostic #else 168540393Sbostic #define ParseReadc() (getc(curFILE)) 168640393Sbostic #endif /* notdef */ 168740393Sbostic 168840424Sbostic 168940393Sbostic /*- 169040393Sbostic *--------------------------------------------------------------------- 169140393Sbostic * ParseReadLine -- 169240393Sbostic * Read an entire line from the input file. Called only by Parse_File. 169340393Sbostic * To facilitate escaped newlines and what have you, a character is 169440393Sbostic * buffered in 'lastc', which is '\0' when no characters have been 169540393Sbostic * read. When we break out of the loop, c holds the terminating 169640393Sbostic * character and lastc holds a character that should be added to 169740393Sbostic * the line (unless we don't read anything but a terminator). 169840393Sbostic * 169940393Sbostic * Results: 170040393Sbostic * A line w/o its newline 170140393Sbostic * 170240393Sbostic * Side Effects: 170340393Sbostic * Only those associated with reading a character 170440393Sbostic *--------------------------------------------------------------------- 170540393Sbostic */ 170640393Sbostic static char * 170740393Sbostic ParseReadLine () 170840393Sbostic { 170940393Sbostic Buffer buf; /* Buffer for current line */ 171040393Sbostic register int c; /* the current character */ 171140393Sbostic register int lastc; /* The most-recent character */ 171240393Sbostic Boolean semiNL; /* treat semi-colons as newlines */ 171340393Sbostic Boolean ignDepOp; /* TRUE if should ignore dependency operators 171440393Sbostic * for the purposes of setting semiNL */ 171540393Sbostic Boolean ignComment; /* TRUE if should ignore comments (in a 171640393Sbostic * shell command */ 171740393Sbostic char *line; /* Result */ 171840393Sbostic int lineLength; /* Length of result */ 171940393Sbostic 172040393Sbostic semiNL = FALSE; 172140393Sbostic ignDepOp = FALSE; 172240393Sbostic ignComment = FALSE; 172340393Sbostic 172440393Sbostic /* 172540393Sbostic * Handle special-characters at the beginning of the line. Either a 172640393Sbostic * leading tab (shell command) or pound-sign (possible conditional) 172740393Sbostic * forces us to ignore comments and dependency operators and treat 172840393Sbostic * semi-colons as semi-colons (by leaving semiNL FALSE). This also 172940393Sbostic * discards completely blank lines. 173040393Sbostic */ 173140393Sbostic while(1) { 173240393Sbostic c = ParseReadc(); 173340393Sbostic 173440435Sbostic if ((c == '\t') || (c == '.')) { 173540393Sbostic ignComment = ignDepOp = TRUE; 173640393Sbostic break; 173740393Sbostic } else if (c == '\n') { 173840393Sbostic lineno++; 173940393Sbostic } else { 174040393Sbostic /* 174140393Sbostic * Anything else breaks out without doing anything 174240393Sbostic */ 174340393Sbostic break; 174440393Sbostic } 174540393Sbostic } 174640393Sbostic 174740393Sbostic if (c != EOF) { 174840393Sbostic lastc = c; 174940393Sbostic buf = Buf_Init(BSIZE); 175040393Sbostic 175140393Sbostic while (((c = ParseReadc ()) != '\n' || (lastc == '\\')) && 175240393Sbostic (c != EOF)) 175340393Sbostic { 175440393Sbostic test_char: 175540393Sbostic switch(c) { 175640393Sbostic case '\n': 175740393Sbostic /* 175840393Sbostic * Escaped newline: read characters until a non-space or an 175940393Sbostic * unescaped newline and replace them all by a single space. 176040393Sbostic * This is done by storing the space over the backslash and 176140393Sbostic * dropping through with the next nonspace. If it is a 176240393Sbostic * semi-colon and semiNL is TRUE, it will be recognized as a 176340393Sbostic * newline in the code below this... 176440393Sbostic */ 176540393Sbostic lineno++; 176640393Sbostic lastc = ' '; 176740393Sbostic while ((c = ParseReadc ()) == ' ' || c == '\t') { 176840393Sbostic continue; 176940393Sbostic } 177040393Sbostic if (c == EOF || c == '\n') { 177140393Sbostic goto line_read; 177240393Sbostic } else { 177340393Sbostic /* 177440393Sbostic * Check for comments, semiNL's, etc. -- easier than 177540393Sbostic * ungetc(c, curFILE); continue; 177640393Sbostic */ 177740393Sbostic goto test_char; 177840393Sbostic } 177940393Sbostic break; 178040393Sbostic case ';': 178140393Sbostic /* 178240393Sbostic * Semi-colon: Need to see if it should be interpreted as a 178340393Sbostic * newline 178440393Sbostic */ 178540393Sbostic if (semiNL) { 178640393Sbostic /* 178740393Sbostic * To make sure the command that may be following this 178840393Sbostic * semi-colon begins with a tab, we push one back into the 178940393Sbostic * input stream. This will overwrite the semi-colon in the 179040393Sbostic * buffer. If there is no command following, this does no 179140393Sbostic * harm, since the newline remains in the buffer and the 179240393Sbostic * whole line is ignored. 179340393Sbostic */ 179440393Sbostic ungetc('\t', curFILE); 179540393Sbostic goto line_read; 179640393Sbostic } 179740393Sbostic break; 179840393Sbostic case '=': 179940393Sbostic if (!semiNL) { 180040393Sbostic /* 180140393Sbostic * Haven't seen a dependency operator before this, so this 180240393Sbostic * must be a variable assignment -- don't pay attention to 180340393Sbostic * dependency operators after this. 180440393Sbostic */ 180540393Sbostic ignDepOp = TRUE; 180640393Sbostic } else if (lastc == ':' || lastc == '!') { 180740393Sbostic /* 180840393Sbostic * Well, we've seen a dependency operator already, but it 180940393Sbostic * was the previous character, so this is really just an 181040393Sbostic * expanded variable assignment. Revert semi-colons to 181140393Sbostic * being just semi-colons again and ignore any more 181240393Sbostic * dependency operators. 181340393Sbostic * 181440393Sbostic * XXX: Note that a line like "foo : a:=b" will blow up, 181540393Sbostic * but who'd write a line like that anyway? 181640393Sbostic */ 181740393Sbostic ignDepOp = TRUE; semiNL = FALSE; 181840393Sbostic } 181940393Sbostic break; 182040393Sbostic case '#': 182140393Sbostic if (!ignComment) { 182240393Sbostic if (backwards || (lastc != '\\')) { 182340393Sbostic /* 182440393Sbostic * If the character is a hash mark and it isn't escaped 182540393Sbostic * (or we're being compatible), the thing is a comment. 182640393Sbostic * Skip to the end of the line. 182740393Sbostic */ 182840393Sbostic do { 182940393Sbostic c = ParseReadc(); 183040393Sbostic } while ((c != '\n') && (c != EOF)); 183140393Sbostic goto line_read; 183240393Sbostic } else { 183340393Sbostic /* 183440393Sbostic * Don't add the backslash. Just let the # get copied 183540393Sbostic * over. 183640393Sbostic */ 183740393Sbostic lastc = c; 183840393Sbostic continue; 183940393Sbostic } 184040393Sbostic } 184140393Sbostic break; 184240393Sbostic case ':': 184340393Sbostic case '!': 184440393Sbostic if (!ignDepOp && (c == ':' || c == '!')) { 184540393Sbostic /* 184640393Sbostic * A semi-colon is recognized as a newline only on 184740393Sbostic * dependency lines. Dependency lines are lines with a 184840393Sbostic * colon or an exclamation point. Ergo... 184940393Sbostic */ 185040393Sbostic semiNL = TRUE; 185140393Sbostic } 185240393Sbostic break; 185340393Sbostic } 185440393Sbostic /* 185540393Sbostic * Copy in the previous character and save this one in lastc. 185640393Sbostic */ 185740393Sbostic Buf_AddByte (buf, (Byte)lastc); 185840393Sbostic lastc = c; 185940393Sbostic 186040393Sbostic } 186140393Sbostic line_read: 186240393Sbostic lineno++; 186340393Sbostic 186440393Sbostic if (lastc != '\0') { 186540393Sbostic Buf_AddByte (buf, (Byte)lastc); 186640393Sbostic } 186740393Sbostic Buf_AddByte (buf, (Byte)'\0'); 186840393Sbostic line = (char *)Buf_GetAll (buf, &lineLength); 186940393Sbostic Buf_Destroy (buf, FALSE); 187040393Sbostic 187140435Sbostic if (line[0] == '.') { 187240393Sbostic /* 187340393Sbostic * The line might be a conditional. Ask the conditional module 187440393Sbostic * about it and act accordingly 187540393Sbostic */ 187640393Sbostic switch (Cond_Eval (line)) { 187740393Sbostic case COND_SKIP: 187840393Sbostic do { 187940393Sbostic /* 188040393Sbostic * Skip to next conditional that evaluates to COND_PARSE. 188140393Sbostic */ 188240393Sbostic free (line); 188340393Sbostic c = ParseReadc(); 188440393Sbostic /* 188540393Sbostic * Skip lines until get to one that begins with a 188640393Sbostic * special char. 188740393Sbostic */ 188840435Sbostic while ((c != '.') && (c != EOF)) { 188940393Sbostic while (((c != '\n') || (lastc == '\\')) && 189040393Sbostic (c != EOF)) 189140393Sbostic { 189240393Sbostic /* 189340393Sbostic * Advance to next unescaped newline 189440393Sbostic */ 189540393Sbostic if ((lastc = c) == '\n') { 189640393Sbostic lineno++; 189740393Sbostic } 189840393Sbostic c = ParseReadc(); 189940393Sbostic } 190040393Sbostic lineno++; 190140393Sbostic 190240393Sbostic lastc = c; 190340393Sbostic c = ParseReadc (); 190440393Sbostic } 190540393Sbostic 190640393Sbostic if (c == EOF) { 190740393Sbostic Parse_Error (PARSE_FATAL, "Unclosed conditional"); 190840393Sbostic return ((char *)NULL); 190940393Sbostic } 191040393Sbostic 191140393Sbostic /* 191240393Sbostic * Read the entire line into buf 191340393Sbostic */ 191440393Sbostic buf = Buf_Init (BSIZE); 191540393Sbostic do { 191640393Sbostic Buf_AddByte (buf, (Byte)c); 191740393Sbostic c = ParseReadc(); 191840393Sbostic } while ((c != '\n') && (c != EOF)); 191940393Sbostic lineno++; 192040393Sbostic 192140393Sbostic Buf_AddByte (buf, (Byte)'\0'); 192240393Sbostic line = (char *)Buf_GetAll (buf, &lineLength); 192340393Sbostic Buf_Destroy (buf, FALSE); 192440393Sbostic } while (Cond_Eval(line) != COND_PARSE); 192540393Sbostic /*FALLTHRU*/ 192640393Sbostic case COND_PARSE: 192740393Sbostic free (line); 192840393Sbostic line = ParseReadLine(); 192940393Sbostic break; 193040393Sbostic } 193140393Sbostic } 193240393Sbostic 193340393Sbostic return (line); 193440393Sbostic } else { 193540393Sbostic /* 193640393Sbostic * Hit end-of-file, so return a NULL line to indicate this. 193740393Sbostic */ 193840393Sbostic return((char *)NULL); 193940393Sbostic } 194040393Sbostic } 194140424Sbostic 194240393Sbostic /*- 194340393Sbostic *----------------------------------------------------------------------- 194440393Sbostic * ParseFinishLine -- 194540393Sbostic * Handle the end of a dependency group. 194640393Sbostic * 194740393Sbostic * Results: 194840393Sbostic * Nothing. 194940393Sbostic * 195040393Sbostic * Side Effects: 195140393Sbostic * inLine set FALSE. 'targets' list destroyed. 195240393Sbostic * 195340393Sbostic *----------------------------------------------------------------------- 195440393Sbostic */ 195540393Sbostic static void 195640393Sbostic ParseFinishLine() 195740393Sbostic { 195840393Sbostic extern int Suff_EndTransform(); 195940393Sbostic 196040393Sbostic if (inLine) { 196140393Sbostic Lst_ForEach(targets, Suff_EndTransform, (ClientData)NULL); 196240393Sbostic Lst_Destroy (targets, ParseHasCommands); 196340393Sbostic inLine = FALSE; 196440393Sbostic } 196540393Sbostic } 196640393Sbostic 196740424Sbostic 196840393Sbostic /*- 196940393Sbostic *--------------------------------------------------------------------- 197040393Sbostic * Parse_File -- 197140393Sbostic * Parse a file into its component parts, incorporating it into the 197240393Sbostic * current dependency graph. This is the main function and controls 197340393Sbostic * almost every other function in this module 197440393Sbostic * 197540393Sbostic * Results: 197640393Sbostic * None 197740393Sbostic * 197840393Sbostic * Side Effects: 197940393Sbostic * Loads. Nodes are added to the list of all targets, nodes and links 198040393Sbostic * are added to the dependency graph. etc. etc. etc. 198140393Sbostic *--------------------------------------------------------------------- 198240393Sbostic */ 198340393Sbostic void 198440393Sbostic Parse_File(name, stream) 198540393Sbostic char *name; /* the name of the file being read */ 198640393Sbostic FILE * stream; /* Stream open to makefile to parse */ 198740393Sbostic { 198840393Sbostic register char *cp, /* pointer into the line */ 198940393Sbostic *line; /* the line we're working on */ 199040393Sbostic 199140393Sbostic inLine = FALSE; 199240393Sbostic fname = name; 199340393Sbostic curFILE = stream; 199440393Sbostic lineno = 0; 199540393Sbostic fatals = 0; 199640393Sbostic 199740393Sbostic do { 199840393Sbostic while (line = ParseReadLine ()) { 199940435Sbostic if (*line == '.') { 200040393Sbostic /* 200140393Sbostic * Lines that begin with the special character are either 200240393Sbostic * include or undef directives. 200340393Sbostic */ 200440393Sbostic for (cp = line + 1; isspace (*cp); cp++) { 200540393Sbostic continue; 200640393Sbostic } 200740393Sbostic if (strncmp (cp, "include", 7) == 0) { 200840393Sbostic ParseDoInclude (cp + 7); 200940393Sbostic goto nextLine; 201040393Sbostic } else if (strncmp(cp, "undef", 5) == 0) { 201140393Sbostic char *cp2; 201240393Sbostic for (cp += 5; isspace(*cp); cp++) { 201340393Sbostic continue; 201440393Sbostic } 201540393Sbostic 201640393Sbostic for (cp2 = cp; !isspace(*cp2) && (*cp2 != '\0'); cp2++) { 201740393Sbostic continue; 201840393Sbostic } 201940393Sbostic 202040393Sbostic *cp2 = '\0'; 202140393Sbostic 202240393Sbostic Var_Delete(cp, VAR_GLOBAL); 202340393Sbostic goto nextLine; 202440393Sbostic } 202540393Sbostic } 202640393Sbostic if (*line == '#') { 202740435Sbostic /* If we're this far, the line must be a comment. */ 202840393Sbostic goto nextLine; 202940393Sbostic } 203040393Sbostic 203140393Sbostic if (*line == '\t' 203240393Sbostic #ifdef POSIX 203340393Sbostic || *line == ' ' 203440393Sbostic #endif 203540393Sbostic ) 203640393Sbostic { 203740393Sbostic /* 203840393Sbostic * If a line starts with a tab (or space in POSIX-land), it 203940393Sbostic * can only hope to be a creation command. 204040393Sbostic */ 204140393Sbostic shellCommand: 204240393Sbostic for (cp = line + 1; isspace (*cp); cp++) { 204340393Sbostic continue; 204440393Sbostic } 204540393Sbostic if (*cp) { 204640393Sbostic if (inLine) { 204740393Sbostic /* 204840393Sbostic * So long as it's not a blank line and we're actually 204940393Sbostic * in a dependency spec, add the command to the list of 205040393Sbostic * commands of all targets in the dependency spec 205140393Sbostic */ 205240393Sbostic Lst_ForEach (targets, ParseAddCmd, (ClientData)cp); 205340393Sbostic continue; 205440393Sbostic } else { 205540393Sbostic Parse_Error (PARSE_FATAL, 205640393Sbostic "Unassociated shell command \"%.20s\"", 205740393Sbostic cp); 205840393Sbostic } 205940393Sbostic } 206040393Sbostic } else if (Parse_IsVar (line)) { 206140393Sbostic ParseFinishLine(); 206240393Sbostic Parse_DoVar (line, VAR_GLOBAL); 206340393Sbostic } else { 206440393Sbostic /* 206540393Sbostic * We now know it's a dependency line so it needs to have all 206640393Sbostic * variables expanded before being parsed. Tell the variable 206740393Sbostic * module to complain if some variable is undefined... 206840393Sbostic * To make life easier on novices, if the line is indented we 206940393Sbostic * first make sure the line has a dependency operator in it. 207040393Sbostic * If it doesn't have an operator and we're in a dependency 207140393Sbostic * line's script, we assume it's actually a shell command 207240393Sbostic * and add it to the current list of targets. 207340393Sbostic * 207440393Sbostic * Note that POSIX declares all lines that start with 207540393Sbostic * whitespace are shell commands, so there's no need to check 207640393Sbostic * here... 207740393Sbostic */ 207840393Sbostic Boolean nonSpace = FALSE; 207940393Sbostic 208040393Sbostic cp = line; 208140393Sbostic #ifndef POSIX 208240393Sbostic if (line[0] == ' ') { 208340393Sbostic while ((*cp != ':') && (*cp != '!') && (*cp != '\0')) { 208440393Sbostic if (!isspace(*cp)) { 208540393Sbostic nonSpace = TRUE; 208640393Sbostic } 208740393Sbostic cp++; 208840393Sbostic } 208940393Sbostic } 209040393Sbostic 209140393Sbostic if (*cp == '\0') { 209240393Sbostic if (inLine) { 209340393Sbostic Parse_Error (PARSE_WARNING, 209440393Sbostic "Shell command needs a leading tab"); 209540393Sbostic goto shellCommand; 209640393Sbostic } else if (nonSpace) { 209740393Sbostic Parse_Error (PARSE_FATAL, "Missing operator"); 209840393Sbostic } 209940393Sbostic } else { 210040393Sbostic #endif 210140393Sbostic ParseFinishLine(); 210240393Sbostic 210340393Sbostic cp = Var_Subst (line, VAR_CMD, TRUE); 210440393Sbostic free (line); 210540393Sbostic line = cp; 210640393Sbostic 210740393Sbostic /* 210840393Sbostic * Need a non-circular list for the target nodes 210940393Sbostic */ 211040393Sbostic targets = Lst_Init (FALSE); 211140393Sbostic inLine = TRUE; 211240393Sbostic 211340393Sbostic ParseDoDependency (line); 211440393Sbostic #ifndef POSIX 211540393Sbostic } 211640393Sbostic #endif 211740393Sbostic } 211840393Sbostic 211940393Sbostic nextLine: 212040393Sbostic 212140393Sbostic free (line); 212240393Sbostic } 212340393Sbostic /* 212440393Sbostic * Reached EOF, but it may be just EOF of an include file... 212540393Sbostic */ 212640393Sbostic } while (ParseEOF() == CONTINUE); 212740393Sbostic 212840393Sbostic /* 212940393Sbostic * Make sure conditionals are clean 213040393Sbostic */ 213140393Sbostic Cond_End(); 213240393Sbostic 213340393Sbostic if (fatals) { 213440393Sbostic fprintf (stderr, "Fatal errors encountered -- cannot continue\n"); 213540393Sbostic exit (1); 213640393Sbostic } 213740393Sbostic } 213840424Sbostic 213940393Sbostic /*- 214040393Sbostic *--------------------------------------------------------------------- 214140393Sbostic * Parse_Init -- 214240393Sbostic * initialize the parsing module 214340393Sbostic * 214440393Sbostic * Results: 214540393Sbostic * none 214640393Sbostic * 214740393Sbostic * Side Effects: 214840393Sbostic * the parseIncPath list is initialized... 214940393Sbostic *--------------------------------------------------------------------- 215040393Sbostic */ 215140393Sbostic Parse_Init () 215240393Sbostic { 215340393Sbostic char *cp; 215440393Sbostic char *start; 215540393Sbostic static char syspath[] = DEFSYSPATH; /* Avoid faults on read-only string 215640393Sbostic * constant... */ 215740393Sbostic 215840393Sbostic mainNode = NILGNODE; 215940393Sbostic parseIncPath = Lst_Init (FALSE); 216040393Sbostic sysIncPath = Lst_Init (FALSE); 216140393Sbostic includes = Lst_Init (FALSE); 216240393Sbostic 216340393Sbostic /* 216440393Sbostic * Add the directories from the DEFSYSPATH (more than one may be given 216540393Sbostic * as dir1:...:dirn) to the system include path. 216640393Sbostic */ 216740393Sbostic for (start = syspath; *start != '\0'; start = cp) { 216840393Sbostic for (cp = start; *cp != '\0' && *cp != ':'; cp++) { 216940393Sbostic ; 217040393Sbostic } 217140393Sbostic if (*cp == '\0') { 217240393Sbostic Dir_AddDir(sysIncPath, start); 217340393Sbostic } else { 217440393Sbostic *cp++ = '\0'; 217540393Sbostic Dir_AddDir(sysIncPath, start); 217640393Sbostic } 217740393Sbostic } 217840393Sbostic } 217940424Sbostic 218040393Sbostic /*- 218140393Sbostic *----------------------------------------------------------------------- 218240393Sbostic * Parse_MainName -- 218340393Sbostic * Return a Lst of the main target to create for main()'s sake. If 218440393Sbostic * no such target exists, we Punt with an obnoxious error message. 218540393Sbostic * 218640393Sbostic * Results: 218740393Sbostic * A Lst of the single node to create. 218840393Sbostic * 218940393Sbostic * Side Effects: 219040393Sbostic * None. 219140393Sbostic * 219240393Sbostic *----------------------------------------------------------------------- 219340393Sbostic */ 219440393Sbostic Lst 219540393Sbostic Parse_MainName() 219640393Sbostic { 219740393Sbostic Lst main; /* result list */ 219840393Sbostic 219940393Sbostic main = Lst_Init (FALSE); 220040393Sbostic 220140393Sbostic if (mainNode == NILGNODE) { 220240393Sbostic Punt ("I don't know what to DO!\n"); 220340393Sbostic /*NOTREACHED*/ 220440393Sbostic } else if (mainNode->type & OP_DOUBLEDEP) { 220540393Sbostic Lst_Concat(main, mainNode->cohorts, LST_CONCNEW); 220640393Sbostic } 220740393Sbostic (void) Lst_AtEnd (main, (ClientData)mainNode); 220840393Sbostic return (main); 220940393Sbostic } 2210