/* * Copyright 1993, 1995 Christopher Seiwald. * * This file is part of Jam - see jam.c for Copyright information. */ #include "Rules.hpp" #include "Hash.hpp" #include "String.hpp" #include "Variable.hpp" using Jam::List; using Jam::String; /* * rules.c - access to RULEs, TARGETs, and ACTIONs * * External routines: * * bindrule() - return pointer to RULE, creating it if necessary * bindtarget() - return pointer to TARGET, creating it if necessary * touchtarget() - mark a target to simulate being new * targetlist() - turn list of target names into a TARGET chain * targetentry() - add a TARGET to a chain of TARGETS * actionlist() - append to an ACTION chain * addsettings() - add a deferred "set" command to a target * usesettings() - set all target specific variables * pushsettings() - set all target specific variables * popsettings() - reset target specific variables to their pre-push values * freesettings() - delete a settings list * donerules() - free RULE and TARGET tables * * 04/12/94 (seiwald) - actionlist() now just appends a single action. * 08/23/94 (seiwald) - Support for '+=' (append to variable) */ static struct hash *rulehash = 0; static struct hash *targethash = 0; /* * bindrule() - return pointer to RULE, creating it if necessary */ RULE * bindrule( const char *rulename ) { RULE rule, *r = &rule; if( !rulehash ) rulehash = hashinit( sizeof( RULE ), "rules" ); r->name = rulename; if( hashenter( rulehash, (HASHDATA **)&r ) ) { r->name = String::newstr( rulename ); /* never freed */ r->procedure = NULL; r->actions = NULL; r->bindlist = NULL; r->flags = 0; } return r; } /* * bindtarget() - return pointer to TARGET, creating it if necessary */ TARGET * bindtarget( const char *targetname ) { TARGET target, *t = ⌖ if( !targethash ) targethash = hashinit( sizeof( TARGET ), "targets" ); t->name = targetname; if( hashenter( targethash, (HASHDATA **)&t ) ) { memset( (char *)t, '\0', sizeof( *t ) ); t->name = String::newstr( (char*)targetname ); /* never freed */ t->boundname = t->name; /* default for T_FLAG_NOTFILE */ } return t; } /* * touchtarget() - mark a target to simulate being new */ void touchtarget( char *t ) { bindtarget( t )->flags |= T_FLAG_TOUCHED; } /* * targetlist() - turn list of target names into a TARGET chain * * Inputs: * chain existing TARGETS to append to * targets list of target names */ TARGETS * targetlist( TARGETS *chain, List *targets ) { for( ; targets; targets = List::list_next( targets ) ) { chain = targetentry( chain, bindtarget( targets->string ) ); } return chain; } /* * targetentry() - add a TARGET to a chain of TARGETS * * Inputs: * chain exisitng TARGETS to append to * target new target to append */ TARGETS * targetentry( TARGETS *chain, TARGET *target ) { TARGETS *c; c = (TARGETS *)malloc( sizeof( TARGETS ) ); c->target = target; if( !chain ) chain = c; else chain->tail->next = c; chain->tail = c; c->next = 0; return chain; } /* * actionlist() - append to an ACTION chain */ ACTIONS * actionlist( ACTIONS *chain, ACTION *action ) { ACTIONS *actions = (ACTIONS *)malloc( sizeof( ACTIONS ) ); actions->action = action; if( !chain ) chain = actions; else chain->tail->next = actions; chain->tail = actions; actions->next = 0; return chain; } /* * addsettings() - add a deferred "set" command to a target * * Adds a variable setting (varname=list) onto a chain of settings * for a particular target. Replaces the previous previous value, * if any, unless 'append' says to append the new list onto the old. * Returns the head of the chain of settings. */ SETTINGS * addsettings( SETTINGS *head, int append, const char *symbol, List *value ) { SETTINGS *v; /* Look for previous setting */ for( v = head; v; v = v->next ) if( !strcmp( v->symbol, symbol ) ) break; /* If not previously set, alloc a new. */ /* If appending, do so. */ /* Else free old and set new. */ if( !v ) { v = (SETTINGS *)malloc( sizeof( *v ) ); v->symbol = String::newstr( symbol ); v->value = value; v->next = head; head = v; } else if( append ) { v->value = List::list_append( v->value, value ); } else { List::list_free( v->value ); v->value = value; } /* Return (new) head of list. */ return head; } /* * pushsettings() - set all target specific variables */ void pushsettings( SETTINGS *v ) { for( ; v; v = v->next ) v->value = var_swap( v->symbol, v->value ); } /* * popsettings() - reset target specific variables to their pre-push values */ void popsettings( SETTINGS *v ) { pushsettings( v ); /* just swap again */ } /* * freesettings() - delete a settings list */ void freesettings( SETTINGS *v ) { while( v ) { SETTINGS *n = v->next; String::freestr( v->symbol ); List::list_free( v->value ); free( (char *)v ); v = n; } } /* * donerules() - free RULE and TARGET tables */ void donerules() { hashdone( rulehash ); hashdone( targethash ); }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#6 | 1162 | bob_summerwill | Converted LIST into a List class, with all static methods. | ||
#5 | 1156 | bob_summerwill | Converted Parse into a class. | ||
#4 | 1153 | bob_summerwill | NewStr has been renamed as String. | ||
#3 | 1146 | bob_summerwill | Moved the NewStr global functions into a static class Jam::String. | ||
#2 | 1138 | bob_summerwill | Removed all extern "C" wrappers, so the program now has C++ linkage throughout, ready for refactoring. | ||
#1 | 1132 | bob_summerwill | All of the non-generated, non-platform-specific files are now mixed-case C++ source files. | ||
//guest/bob_summerwill/jam/src/rules.c | |||||
#5 | 1130 | bob_summerwill | More .C to .CPP conversions. | ||
#4 | 1127 | bob_summerwill | More file renaming. | ||
#3 | 1126 | bob_summerwill | #include dependencies between headers are now modelled explicitly, with #includes as required in header files, rather than it being a client-code responsibility. | ||
#2 | 1120 | bob_summerwill | A fair-size chunk of char* const-correctness modifications. | ||
#1 | 1106 | bob_summerwill | Integrated Jam from "public" to "guest/bob_summerwill". | ||
//guest/perforce_software/jam/src/rules.c | |||||
#2 | 486 | Perforce staff |
Jam 2.3. See RELNOTES for a list of changes from 2.2.x. Just about every source file was touched when jam got ANSI-fied. |
||
#1 | 2 | laura | Add Jam/MR 2.2 source |