LIST * compile_rule( PARSE *parse, LOL *args, int *jmp ) { LOL nargs[1]; LIST *result = 0; LIST *ll; LISTITEM *l; PARSE *p; /* list of rules to run -- normally 1! */ ll = (*parse->left->func)( parse->left, args, jmp ); /* Build up the list of arg lists */ lol_init( nargs ); for( p = parse->right; p; p = p->left ) lol_add( nargs, (*p->right->func)( p->right, args, jmp ) ); /* Run rules, appending results from each */ for( l = list_first(ll); l; l = list_next( l ) ) { list_free(result); /* Keep only last result */ result = evaluate_rule( list_value(l), nargs, result ); } list_free( ll ); lol_free( nargs ); return result; }
int LS_jam_evaluaterule(ls_lua_State *L) { LOL lol; int i; LIST *list; int index; int numParams = ls_lua_gettop(L); if (numParams < 1) return 0; if (!ls_lua_isstring(L, 1)) return 0; lol_init(&lol); for (i = 0; i < numParams - 1; ++i) { lol_add(&lol, luahelper_addtolist(L, L0, 2 + i)); } list = evaluate_rule(ls_lua_tostring(L, 1), &lol, L0); lol_free(&lol); ls_lua_newtable(L); index = 1; for (; list; list = list_next(list), ++index) { ls_lua_pushnumber(L, index); ls_lua_pushstring(L, list->string); ls_lua_settable(L, -3); } return 1; }
void cmd_free( CMD * cmd ) { lol_free( &cmd->args ); list_free( cmd->shell ); string_free( cmd->buf ); BJAM_FREE( (void *)cmd ); }
void headers( TARGET *t ) { LIST *hdrscan; LIST *hdrrule; LIST *hdrcache; LOL lol; if( !( hdrscan = var_get( "HDRSCAN" ) ) || !( hdrrule = var_get( "HDRRULE" ) ) ) return; /* Doctor up call to HDRRULE rule */ /* Call headers1() to get LIST of included files. */ if( DEBUG_HEADER ) printf( "header scan %s\n", t->name ); lol_init( &lol ); lol_add( &lol, list_new( L0, t->name, 1 ) ); lol_add( &lol, headers1( t->boundname, hdrscan ) ); if( lol_get( &lol, 1 ) ) list_free( evaluate_rule( 0, hdrrule->string, &lol, L0 ) ); /* Clean up */ lol_free( &lol ); }
void var_expand_unit_test() { LOL lol[1]; LIST* l, *l2; LIST *expected = list_new( list_new( L0, newstr( "axb" ) ), newstr( "ayb" ) ); LIST *e2; char axyb[] = "a$(xy)b"; char azb[] = "a$($(z))b"; lol_init(lol); var_set("xy", list_new( list_new( L0, newstr( "x" ) ), newstr( "y" ) ), VAR_SET ); var_set("z", list_new( L0, newstr( "xy" ) ), VAR_SET ); l = var_expand( 0, axyb, axyb + sizeof(axyb) - 1, lol, 0 ); for ( l2 = l, e2 = expected; l2 && e2; l2 = list_next(l2), e2 = list_next(e2) ) assert( !strcmp( e2->string, l2->string ) ); list_free(l); l = var_expand( 0, azb, azb + sizeof(azb) - 1, lol, 0 ); for ( l2 = l, e2 = expected; l2 && e2; l2 = list_next(l2), e2 = list_next(e2) ) assert( !strcmp( e2->string, l2->string ) ); list_free(l); list_free(expected); lol_free(lol); }
/* * args_free() - release a reference to the given argument list */ void args_free( argument_list* a ) { if (--a->reference_count <= 0) { lol_free(a->data); free(a); } }
void cmd_free( CMD *cmd ) { lol_free( &cmd->args ); list_free( cmd->shell ); free( cmd->buf ); free( (char *)cmd ); }
void cmd_free( CMD * cmd ) { cmdlist_free( cmd->next ); lol_free( &cmd->args ); list_free( cmd->shell ); string_free( cmd->buf ); freetargets( cmd->unlock ); BJAM_FREE( (void *)cmd ); }
LIST * headers1( const char *file, LIST *hdrscan ) { FILE *f; LIST *result = 0; LIST *hdrpipe; LIST *hdrpipefile; if ( list_first(hdrpipe = var_get( "HDRPIPE" )) ) { LOL args; BUFFER buff; lol_init( &args ); lol_add( &args, list_append( L0, file, 0 ) ); buffer_init( &buff ); if ( var_string( list_value(list_first(hdrpipe)), &buff, 0, &args, ' ') < 0 ) { printf( "Cannot expand HDRPIPE '%s' !\n", list_value(list_first(hdrpipe)) ); exit( EXITBAD ); } buffer_addchar( &buff, 0 ); if ( !( f = file_popen( (const char*)buffer_ptr( &buff ), "r" ) ) ) { buffer_free( &buff ); return result; } buffer_free( &buff ); lol_free( &args ); } else { if( !( f = fopen( file, "r" ) ) ) return result; } result = headers1helper( f, hdrscan ); if ( list_first(hdrpipe) ) file_pclose( f ); else fclose( f ); if ( list_first(hdrpipefile = var_get( "HDRPIPEFILE" )) ) { if( !( f = fopen( list_value(list_first(hdrpipefile)), "r" ) ) ) return result; result = headers1helper( f, hdrscan ); fclose( f ); } return result; }
void var_expand_unit_test() { LOL lol[1]; LIST* l, *l2; LIST *expected = list_new( list_new( L0, newstr( "axb" ) ), newstr( "ayb" ) ); LIST *e2; char axyb[] = "a$(xy)b"; char azb[] = "a$($(z))b"; char path[] = "$(p:W)"; # ifdef OS_CYGWIN char cygpath[256]; cygwin_conv_to_posix_path("c:\\foo\\bar", cygpath); # else char cygpath[] = "/cygdrive/c/foo/bar"; # endif lol_init(lol); var_set("xy", list_new( list_new( L0, newstr( "x" ) ), newstr( "y" ) ), VAR_SET ); var_set("z", list_new( L0, newstr( "xy" ) ), VAR_SET ); var_set("p", list_new( L0, newstr( cygpath ) ), VAR_SET ); l = var_expand( 0, axyb, axyb + sizeof(axyb) - 1, lol, 0 ); for ( l2 = l, e2 = expected; l2 && e2; l2 = list_next(l2), e2 = list_next(e2) ) assert( !strcmp( e2->string, l2->string ) ); assert(l2 == 0 && e2 == 0); list_free(l); l = var_expand( 0, azb, azb + sizeof(azb) - 1, lol, 0 ); for ( l2 = l, e2 = expected; l2 && e2; l2 = list_next(l2), e2 = list_next(e2) ) assert( !strcmp( e2->string, l2->string ) ); assert(l2 == 0 && e2 == 0); list_free(l); l = var_expand( 0, path, path + sizeof(path) - 1, lol, 0 ); assert(l != 0); assert(list_next(l) == 0); # ifdef OS_CYGWIN assert( !strcmp( l->string, "c:\\foo\\bar" ) ); # else assert( !strcmp( l->string, cygpath ) ); # endif list_free(l); list_free(expected); lol_free(lol); }
LIST * compile_rule( PARSE *parse, LOL *args, int *jmp ) { LOL nargs[1]; LIST *result = 0; LIST *ll, *l; PARSE *p; /* list of rules to run -- normally 1! */ ll = (*parse->left->func)( parse->left, args, jmp ); /* Build up the list of arg lists */ lol_init( nargs ); for( p = parse->right; p; p = p->left ) lol_add( nargs, (*p->right->func)( p->right, args, jmp ) ); /* Run rules, appending results from each */ for( l = ll; l; l = list_next( l ) ) { int localJmp = JMP_NONE; result = evaluate_rule( l->string, nargs, result, &localJmp ); if (localJmp == JMP_EOF) { *jmp = JMP_EOF; break; } } list_free( ll ); lol_free( nargs ); return result; }
void headers( TARGET *t ) { LIST *hdrscan; LIST *hdrrule; LOL lol; if( !list_first( hdrscan = var_get( "HDRSCAN" ) ) || !list_first( hdrrule = var_get( "HDRRULE" ) ) ) return; /* Doctor up call to HDRRULE rule */ /* Call headers1() to get LIST of included files. */ if( DEBUG_HEADER ) printf( "header scan %s\n", t->name ); lol_init( &lol ); lol_add( &lol, list_append( L0, t->name, 1 ) ); #ifdef OPT_HEADER_CACHE_EXT lol_add( &lol, hcache( t, hdrscan ) ); #else lol_add( &lol, headers1( t->boundname, hdrscan ) ); #endif if( list_first(lol_get( &lol, 1 )) ) { #ifdef OPT_HDRRULE_BOUNDNAME_ARG_EXT /* The third argument to HDRRULE is the bound name of * $(<) */ lol_add( &lol, list_append( L0, t->boundname, 0 ) ); #endif list_free( evaluate_rule( list_value(list_first(hdrrule)), &lol, L0 ) ); } /* Clean up */ lol_free( &lol ); }
int LS_jam_evaluaterule(ls_lua_State *L) { LOL lol; int i; LIST *list; LISTITEM* item; int index; const char* rule; int numParams = ls_lua_gettop(L); if (numParams < 1) return 0; if (!ls_lua_isstring(L, 1)) return 0; lol_init(&lol); rule = ls_lua_tostring(L, 1); for (i = 0; i < numParams - 1; ++i) { lol_add(&lol, luahelper_addtolist(L, L0, 2 + i)); } list = evaluate_rule(rule, &lol, L0); lol_free(&lol); ls_lua_newtable(L); index = 1; for (item = list_first(list); item; item = list_next(item), ++index) { ls_lua_pushnumber(L, index); ls_lua_pushstring(L, list_value(item)); ls_lua_settable(L, -3); } return 1; }
void frame_free( FRAME* frame ) { lol_free( frame->args ); }
LIST * evaluate_rule( const char *rulename, LOL *args, LIST *result ) { #ifdef OPT_EXPAND_RULE_NAMES_EXT RULE *rule; char *expanded; char *c; int i; BUFFER buff; buffer_init( &buff ); if( (i = var_string( rulename, &buff, 0, args, ' ' )) < 0 ) { printf( "Failed to expand rule %s -- expansion too long\n", rulename ); exit( EXITBAD ); } expanded = buffer_ptr( &buff ); while ( expanded[0] == ' ' ) expanded++; while ( (c = strrchr(expanded, ' ')) ) *c = '\0'; if( DEBUG_COMPILE ) { debug_compile( 1, rulename ); if ( strcmp(rulename, expanded) ) printf( "-> %s ", expanded ); lol_print( args ); printf( "\n" ); } rule = bindrule( expanded ); #else RULE *rule = bindrule( rulename ); if( DEBUG_COMPILE ) { debug_compile( 1, rulename ); lol_print( args ); printf( "\n" ); } #endif #ifdef OPT_LOAD_MISSING_RULE_EXT if( !rule->actions && !rule->procedure ) { if( ruleexists( "FindMissingRule" ) ) { LOL lol; LIST *args = list_append( L0, expanded, 0 ); LIST *result; lol_init( &lol ); lol_add( &lol, args ); result = evaluate_rule( "FindMissingRule", &lol, L0 ); lol_free( &lol ); if( list_first( result ) ) { rule = bindrule( list_value( list_first( result ) ) ); } list_free( result ); } } #endif /* OPT_LOAD_MISSING_RULE_EXT */ /* Check traditional targets $(<) and sources $(>) */ #ifdef OPT_IMPROVED_WARNINGS_EXT if( !rule->actions && !rule->procedure && !globs.silence ) printf( "warning: unknown rule %s %s\n", rule->name, file_and_line()); #else if( !rule->actions && !rule->procedure ) printf( "warning: unknown rule %s\n", rule->name ); #endif /* If this rule will be executed for updating the targets */ /* then construct the action for make(). */ if( rule->actions ) { TARGETS *t; ACTION *action; /* The action is associated with this instance of this rule */ action = (ACTION *)malloc( sizeof( ACTION ) ); memset( (char *)action, '\0', sizeof( *action ) ); action->rule = rule; #ifdef OPT_BUILTIN_NEEDS_EXT action->targets = targetlist( (TARGETS *)0, lol_get( args, 0 ), 0 ); action->sources = targetlist( (TARGETS *)0, lol_get( args, 1 ), 0 ); action->autosettings = targetlist( (TARGETS *)0, lol_get( args, 2 ), 0 ); #else action->targets = targetlist( (TARGETS *)0, lol_get( args, 0 ) ); action->sources = targetlist( (TARGETS *)0, lol_get( args, 1 ) ); #endif #ifdef OPT_USE_CHECKSUMS_EXT action->extratargets = targetlist( (TARGETS *)0, lol_get( args, 3 ), 0 ); #endif /* OPT_USE_CHECKSUMS_EXT */ #ifdef OPT_CLEAN_GLOBS_EXT { TARGETS* targets; for ( targets = action->targets; targets; targets = targets->next ) { if ( !( targets->target->flags & T_FLAG_NOTFILE ) ) add_used_target_to_hash( targets->target ); } } #endif /* OPT_CLEAN_GLOBS_EXT */ /* Append this action to the actions of each target */ #ifdef OPT_MULTIPASS_EXT action->pass = actionpass; for( t = action->targets; t; t = t->next ) { t->target->progress = T_MAKE_INIT; t->target->actions = actionlist( t->target->actions, action ); } #else for( t = action->targets; t; t = t->next ) t->target->actions = actionlist( t->target->actions, action ); #endif } /* Now recursively compile any parse tree associated with this rule */ if( rule->procedure ) { PARSE *parse = rule->procedure; SETTINGS *s = 0; int jmp = JMP_NONE; LISTITEM *l; int i; /* build parameters as local vars */ for( l = list_first(rule->params), i = 0; l; l = list_next(l), i++ ) s = addsettings( s, 0, list_value(l), list_copy( L0, lol_get( args, i ) ) ); /* Run rule. */ /* Bring in local params. */ /* refer/free to ensure rule not freed during use. */ parse_refer( parse ); pushsettings( s ); result = list_appendList( result, (*parse->func)( parse, args, &jmp ) ); popsettings( s ); freesettings( s ); parse_free( parse ); } if( DEBUG_COMPILE ) debug_compile( -1, 0 ); #ifdef OPT_EXPAND_RULE_NAMES_EXT buffer_free( &buff ); #endif return result; }
LIST * hcache( TARGET *t, LIST *hdrscan ) { HCACHEDATA cachedata, *c = &cachedata; HCACHEFILE *file; LIST *l = 0; int use_cache = 1; const char *target; # ifdef DOWNSHIFT_PATHS char path[ MAXJPATH ]; char *p; # endif target = t->boundname; # ifdef DOWNSHIFT_PATHS p = path; do *p++ = (char)tolower( *target ); while( *target++ ); target = path; # endif ++queries; c->boundname = target; file = hcachefile_get( t ); // if ( file ) { if( hashcheck( file->hcachehash, (HASHDATA **) &c ) ) { #ifdef OPT_BUILTIN_MD5CACHE_EXT if( c->time == t->time && md5matchescommandline( t ) ) #else if( c->time == t->time ) #endif { LIST *l1 = hdrscan, *l2 = c->hdrscan; while( l1 && l2 ) { if( l1->string != l2->string ) { l1 = 0; } else { l1 = list_next( l1 ); l2 = list_next( l2 ); } } if( l1 || l2 ) use_cache = 0; } else use_cache = 0; if( use_cache ) { if( DEBUG_HEADER ) printf( "using header cache for %s\n", t->boundname ); c->age = 0; /* The entry has been used, its young again */ ++hits; l = list_copy( 0, c->includes ); { LIST *hdrfilter = var_get( "HDRFILTER" ); if ( hdrfilter ) { LOL lol; lol_init( &lol ); lol_add( &lol, list_new( L0, t->name, 1 ) ); lol_add( &lol, l ); lol_add( &lol, list_new( L0, t->boundname, 0 ) ); l = evaluate_rule( hdrfilter->string, &lol, L0 ); lol_free( &lol ); } } return l; } else { if( DEBUG_HEADER ) printf( "header cache out of date for %s\n", t->boundname ); list_free( c->includes ); list_free( c->hdrscan ); c->includes = 0; c->hdrscan = 0; } } else { if( hashenter( file->hcachehash, (HASHDATA **)&c ) ) { c->boundname = newstr( c->boundname ); c->next = file->hcachelist; file->hcachelist = c; #ifdef OPT_BUILTIN_MD5CACHE_EXT c->mtime = 0; memset( &c->rulemd5sum, 0, MD5_SUMSIZE ); memset( &c->currentrulemd5sum, 0, MD5_SUMSIZE ); memset( &c->contentmd5sum, 0, MD5_SUMSIZE ); memset( &c->currentcontentmd5sum, 0, MD5_SUMSIZE ); #endif } } } file->dirty = 1; /* 'c' points at the cache entry. Its out of date. */ l = headers1( c->boundname, hdrscan ); l = list_append( list_copy( 0, var_get( "HDREXTRA" ) ), l ); c->includes = list_copy( 0, l ); { LIST *hdrfilter = var_get( "HDRFILTER" ); if ( hdrfilter ) { LOL lol; lol_init( &lol ); lol_add( &lol, list_new( L0, t->name, 1 ) ); lol_add( &lol, l ); lol_add( &lol, list_new( L0, t->boundname, 0 ) ); l = evaluate_rule( hdrfilter->string, &lol, L0 ); lol_free( &lol ); } } c->time = t->time; c->age = 0; c->hdrscan = list_copy( 0, hdrscan ); return l; }