=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/make/targ.c,v retrieving revision 1.26 retrieving revision 1.27 diff -c -r1.26 -r1.27 *** src/usr.bin/make/targ.c 2000/09/14 13:32:08 1.26 --- src/usr.bin/make/targ.c 2000/09/14 13:40:03 1.27 *************** *** 1,4 **** ! /* $OpenBSD: targ.c,v 1.26 2000/09/14 13:32:08 espie Exp $ */ /* $NetBSD: targ.c,v 1.11 1997/02/20 16:51:50 christos Exp $ */ /* --- 1,4 ---- ! /* $OpenBSD: targ.c,v 1.27 2000/09/14 13:40:03 espie Exp $ */ /* $NetBSD: targ.c,v 1.11 1997/02/20 16:51:50 christos Exp $ */ /* *************** *** 41,49 **** /*- * targ.c -- ! * Functions for maintaining the Lst allTargets. Target nodes are ! * kept in two structures: a Lst, maintained by the list library, and a ! * hash table, maintained by the hash library. * * Interface: * Targ_Init Initialization procedure. --- 41,47 ---- /*- * targ.c -- ! * Target nodes are kept into a hash table. * * Interface: * Targ_Init Initialization procedure. *************** *** 77,86 **** * print something for suffixes, too, but... */ #include #include #include "make.h" ! #include "hash.h" #include "dir.h" #ifndef lint --- 75,86 ---- * print something for suffixes, too, but... */ + #include #include #include #include "make.h" ! #include "ohash.h" ! #include "hash.h" #include "dir.h" #ifndef lint *************** *** 88,108 **** static char sccsid[] = "@(#)targ.c 8.2 (Berkeley) 3/19/94"; #else UNUSED ! static char *rcsid = "$OpenBSD: targ.c,v 1.26 2000/09/14 13:32:08 espie Exp $"; #endif #endif /* not lint */ - static LIST allTargets; /* the list of all targets found so far */ #ifdef CLEANUP static LIST allGNs; /* List of all the GNodes */ #endif ! static Hash_Table targets; /* a hash table of same */ ! #define HTSIZE 191 /* initial size of hash table */ ! ! static void TargPrintOnlySrc __P((void *)); static void TargPrintName __P((void *)); ! static void TargPrintNode __P((void *, void *)); #ifdef CLEANUP static void TargFreeGN __P((void *)); #endif --- 88,108 ---- static char sccsid[] = "@(#)targ.c 8.2 (Berkeley) 3/19/94"; #else UNUSED ! static char *rcsid = "$OpenBSD: targ.c,v 1.27 2000/09/14 13:40:03 espie Exp $"; #endif #endif /* not lint */ #ifdef CLEANUP static LIST allGNs; /* List of all the GNodes */ #endif ! static struct hash targets; /* a hash table of same */ ! static struct hash_info gnode_info = { ! offsetof(GNode, name), ! NULL, hash_alloc, hash_free, element_alloc }; ! static void TargPrintOnlySrc __P((GNode *)); static void TargPrintName __P((void *)); ! static void TargPrintNode __P((GNode *, int)); #ifdef CLEANUP static void TargFreeGN __P((void *)); #endif *************** *** 113,119 **** * Initialize this module * * Side Effects: ! * The allTargets list and the targets hash table are initialized *----------------------------------------------------------------------- */ void --- 113,119 ---- * Initialize this module * * Side Effects: ! * The targets hash table is initialized *----------------------------------------------------------------------- */ void *************** *** 122,129 **** #ifdef CLEANUP Lst_Init(&allGNs); #endif ! Lst_Init(&allTargets); ! Hash_InitTable(&targets, HTSIZE); } /*- --- 122,129 ---- #ifdef CLEANUP Lst_Init(&allGNs); #endif ! /* A small make file already creates 200 targets. */ ! hash_init(&targets, 10, &gnode_info); } /*- *************** *** 131,139 **** * Targ_End -- * Finalize this module * - * Results: - * None - * * Side Effects: * All lists and gnodes are cleared *----------------------------------------------------------------------- --- 131,136 ---- *************** *** 142,150 **** Targ_End () { #ifdef CLEANUP - Lst_Destroy(&allTargets, NOFREE); Lst_Destroy(&allGNs, TargFreeGN); ! Hash_DeleteTable(&targets); #endif } --- 139,146 ---- Targ_End () { #ifdef CLEANUP Lst_Destroy(&allGNs, TargFreeGN); ! hash_delete(&targets); #endif } *************** *** 158,175 **** * of the passed name * * Side Effects: ! * The gnode is added to the list of all gnodes. *----------------------------------------------------------------------- */ GNode * ! Targ_NewGN (name) ! char *name; /* the name to stick in the new node */ { ! register GNode *gn; ! gn = (GNode *) emalloc (sizeof (GNode)); ! gn->name = estrdup (name); ! gn->path = (char *) 0; if (name[0] == '-' && name[1] == 'l') { gn->type = OP_LIB; } else { --- 154,171 ---- * of the passed name * * Side Effects: ! * The gnode is added to the set of all gnodes. *----------------------------------------------------------------------- */ GNode * ! Targ_NewGN(name, end) ! const char *name; /* the name to stick in the new node */ ! const char *end; { ! GNode *gn; ! gn = hash_create_entry(&gnode_info, name, &end); ! gn->path = NULL; if (name[0] == '-' && name[1] == 'l') { gn->type = OP_LIB; } else { *************** *** 197,203 **** Lst_AtEnd(&allGNs, gn); #endif ! return (gn); } #ifdef CLEANUP --- 193,199 ---- Lst_AtEnd(&allGNs, gn); #endif ! return gn; } #ifdef CLEANUP *************** *** 219,226 **** { GNode *gn = (GNode *) gnp; - - free(gn->name); efree(gn->path); Lst_Destroy(&gn->iParents, NOFREE); Lst_Destroy(&gn->cohorts, NOFREE); --- 215,220 ---- *************** *** 250,282 **** *----------------------------------------------------------------------- */ GNode * ! Targ_FindNode (name, flags) ! char *name; /* the name to find */ ! int flags; /* flags governing events when target not * found */ { ! GNode *gn; /* node in that element */ ! Hash_Entry *he; /* New or used hash entry for node */ ! Boolean isNew; /* Set TRUE if Hash_CreateEntry had to create */ ! /* an entry for the node */ ! if (flags & TARG_CREATE) { ! he = Hash_CreateEntry (&targets, name, &isNew); ! if (isNew) { ! gn = Targ_NewGN (name); ! Hash_SetValue (he, gn); ! Lst_AtEnd(&allTargets, gn); ! } ! } else { ! he = Hash_FindEntry (&targets, name); } ! if (he == NULL) { ! return (NULL); ! } else { ! return ((GNode *) Hash_GetValue (he)); ! } } /*- --- 244,268 ---- *----------------------------------------------------------------------- */ GNode * ! Targ_FindNode(name, flags) ! const char *name; /* the name to find */ ! int flags; /* flags governing events when target not * found */ { ! const char *end = NULL; ! GNode *gn; /* node in that element */ ! unsigned int slot; + slot = hash_qlookupi(&targets, name, &end); ! gn = hash_find(&targets, slot); ! ! if (gn == NULL && (flags & TARG_CREATE)) { ! gn = Targ_NewGN(name, end); ! hash_insert(&targets, slot, gn); } ! return gn; } /*- *************** *** 319,387 **** *----------------------------------------------------------------------- * Targ_Ignore -- * Return true if should ignore errors when creating gn - * - * Results: - * TRUE if should ignore errors - * - * Side Effects: - * None *----------------------------------------------------------------------- */ Boolean ! Targ_Ignore (gn) GNode *gn; /* node to check for */ { ! if (ignoreErrors || gn->type & OP_IGNORE) { ! return (TRUE); ! } else { ! return (FALSE); ! } } /*- *----------------------------------------------------------------------- * Targ_Silent -- * Return true if be silent when creating gn - * - * Results: - * TRUE if should be silent - * - * Side Effects: - * None *----------------------------------------------------------------------- */ Boolean ! Targ_Silent (gn) GNode *gn; /* node to check for */ { ! if (beSilent || gn->type & OP_SILENT) { ! return (TRUE); ! } else { ! return (FALSE); ! } } /*- *----------------------------------------------------------------------- * Targ_Precious -- * See if the given target is precious - * - * Results: - * TRUE if it is precious. FALSE otherwise - * - * Side Effects: - * None *----------------------------------------------------------------------- */ Boolean Targ_Precious (gn) GNode *gn; /* the node to check */ { ! if (allPrecious || (gn->type & (OP_PRECIOUS|OP_DOUBLEDEP))) { ! return (TRUE); ! } else { ! return (FALSE); ! } } /******************* DEBUG INFO PRINTING ****************/ --- 305,352 ---- *----------------------------------------------------------------------- * Targ_Ignore -- * Return true if should ignore errors when creating gn *----------------------------------------------------------------------- */ Boolean ! Targ_Ignore(gn) GNode *gn; /* node to check for */ { ! if (ignoreErrors || gn->type & OP_IGNORE) ! return TRUE; ! else ! return FALSE; } /*- *----------------------------------------------------------------------- * Targ_Silent -- * Return true if be silent when creating gn *----------------------------------------------------------------------- */ Boolean ! Targ_Silent(gn) GNode *gn; /* node to check for */ { ! if (beSilent || gn->type & OP_SILENT) ! return TRUE; ! else ! return FALSE; } /*- *----------------------------------------------------------------------- * Targ_Precious -- * See if the given target is precious *----------------------------------------------------------------------- */ Boolean Targ_Precious (gn) GNode *gn; /* the node to check */ { ! if (allPrecious || (gn->type & (OP_PRECIOUS|OP_DOUBLEDEP))) ! return TRUE; ! else ! return FALSE; } /******************* DEBUG INFO PRINTING ****************/ *************** *** 393,407 **** * Set our idea of the main target we'll be creating. Used for * debugging output. * - * Results: - * None. - * * Side Effects: * "mainTarg" is set to the main target's node. *----------------------------------------------------------------------- */ void ! Targ_SetMain (gn) GNode *gn; /* The main target we'll create */ { mainTarg = gn; --- 358,369 ---- * Set our idea of the main target we'll be creating. Used for * debugging output. * * Side Effects: * "mainTarg" is set to the main target's node. *----------------------------------------------------------------------- */ void ! Targ_SetMain(gn) GNode *gn; /* The main target we'll create */ { mainTarg = gn; *************** *** 439,449 **** *----------------------------------------------------------------------- */ char * ! Targ_FmtTime (time) time_t time; { struct tm *parts; ! static char buf[128]; parts = localtime(&time); strftime(buf, sizeof buf, "%k:%M:%S %b %d, %Y", parts); --- 401,411 ---- *----------------------------------------------------------------------- */ char * ! Targ_FmtTime(time) time_t time; { struct tm *parts; ! static char buf[128]; parts = localtime(&time); strftime(buf, sizeof buf, "%k:%M:%S %b %d, %Y", parts); *************** *** 456,473 **** * Targ_PrintType -- * Print out a type field giving only those attributes the user can * set. - * - * Results: - * - * Side Effects: - * *----------------------------------------------------------------------- */ void ! Targ_PrintType (type) ! register int type; { ! register int tbit; #ifdef __STDC__ #define PRINTBIT(attr) case CONCAT(OP_,attr): printf("." #attr " "); break --- 418,430 ---- * Targ_PrintType -- * Print out a type field giving only those attributes the user can * set. *----------------------------------------------------------------------- */ void ! Targ_PrintType(type) ! int type; { ! int tbit; #ifdef __STDC__ #define PRINTBIT(attr) case CONCAT(OP_,attr): printf("." #attr " "); break *************** *** 509,520 **** *----------------------------------------------------------------------- */ static void ! TargPrintNode(gnp, passp) ! void *gnp; ! void *passp; { - GNode *gn = (GNode *)gnp; - int pass = *(int *)passp; if (!OP_NOP(gn->type)) { printf("#\n"); if (gn == mainTarg) --- 466,475 ---- *----------------------------------------------------------------------- */ static void ! TargPrintNode(gn, pass) ! GNode *gn; ! int pass; { if (!OP_NOP(gn->type)) { printf("#\n"); if (gn == mainTarg) *************** *** 567,574 **** fputc('\n', stdout); Lst_Every(&gn->commands, Targ_PrintCmd); printf("\n\n"); ! if (gn->type & OP_DOUBLEDEP) ! Lst_ForEach(&gn->cohorts, TargPrintNode, &pass); } } --- 522,533 ---- fputc('\n', stdout); Lst_Every(&gn->commands, Targ_PrintCmd); printf("\n\n"); ! if (gn->type & OP_DOUBLEDEP) { ! LstNode ln; ! ! for (ln = Lst_First(&gn->cohorts); ln != NULL; ln = Lst_Adv(ln)) ! TargPrintNode((GNode *)Lst_Datum(ln), pass); ! } } } *************** *** 576,593 **** *----------------------------------------------------------------------- * TargPrintOnlySrc -- * Print only those targets that are just a source. - * - * Side Effects: - * The name of each file is printed preceeded by #\t - * *----------------------------------------------------------------------- */ static void ! TargPrintOnlySrc(gnp) ! void *gnp; { - GNode *gn = (GNode *)gnp; - if (OP_NOP(gn->type)) printf("#\t%s [%s]\n", gn->name, gn->path ? gn->path : gn->name); } --- 535,546 ---- *----------------------------------------------------------------------- * TargPrintOnlySrc -- * Print only those targets that are just a source. *----------------------------------------------------------------------- */ static void ! TargPrintOnlySrc(gn) ! GNode *gn; { if (OP_NOP(gn->type)) printf("#\t%s [%s]\n", gn->name, gn->path ? gn->path : gn->name); } *************** *** 595,619 **** /*- *----------------------------------------------------------------------- * Targ_PrintGraph -- ! * print the entire graph. heh heh ! * ! * Results: ! * none ! * ! * Side Effects: ! * lots o' output *----------------------------------------------------------------------- */ void ! Targ_PrintGraph (pass) ! int pass; /* Which pass this is. 1 => no processing ! * 2 => processing done */ { printf("#*** Input graph:\n"); ! Lst_ForEach(&allTargets, TargPrintNode, &pass); printf("\n\n"); printf("#\n# Files that are only sources:\n"); ! Lst_Every(&allTargets, TargPrintOnlySrc); printf("#*** Global Variables:\n"); Var_Dump(VAR_GLOBAL); printf("#*** Command-line Variables:\n"); --- 548,573 ---- /*- *----------------------------------------------------------------------- * Targ_PrintGraph -- ! * print the entire graph. *----------------------------------------------------------------------- */ void ! Targ_PrintGraph(pass) ! int pass; /* Which pass this is. 1 => no processing ! * 2 => processing done */ { + GNode *gn; + unsigned int i; + printf("#*** Input graph:\n"); ! for (gn = hash_first(&targets, &i); gn != NULL; ! gn = hash_next(&targets, &i)) ! TargPrintNode(gn, pass); printf("\n\n"); printf("#\n# Files that are only sources:\n"); ! for (gn = hash_first(&targets, &i); gn != NULL; ! gn = hash_next(&targets, &i)) ! TargPrintOnlySrc(gn); printf("#*** Global Variables:\n"); Var_Dump(VAR_GLOBAL); printf("#*** Command-line Variables:\n");