/* * Copyright 1993, 2000 Christopher Seiwald. * * This file is part of Jam - see jam.c for Copyright information. */ /* * headers.c - handle #includes in source files * * Using regular expressions provided as the variable $(HDRSCAN), * headers() searches a file for #include files and phonies up a * rule invocation: * * $(HDRRULE) <target> : <include files> ; * * External routines: * headers() - scan a target for include files and call HDRRULE * * Internal routines: * headers1() - using regexp, scan a file and build include LIST * * 04/13/94 (seiwald) - added shorthand L0 for null list pointer * 09/10/00 (seiwald) - replaced call to compile_rule with evaluate_rule, * so that headers() doesn't have to mock up a parse structure * just to invoke a rule. * 03/02/02 (seiwald) - rules can be invoked via variable names * 10/22/02 (seiwald) - list_new() now does its own newstr()/copystr() * 11/04/02 (seiwald) - const-ing for string literals * 12/09/02 (seiwald) - push regexp creation down to headers1(). * 01/05/07 (seiwald) - evaluate_rule takes PARSE for debugging. */ # include "jam.h" # include "lists.h" # include "parse.h" # include "compile.h" # include "rules.h" # include "variable.h" # include "regexp.h" # include "headers.h" # include "newstr.h" static LIST *headers1( const char *file, LIST *hdrscan ); /* * headers() - scan a target for include files and call HDRRULE */ # define MAXINC 10 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 ); } /* * headers1() - using regexp, scan a file and build include LIST */ static LIST * headers1( const char *file, LIST *hdrscan ) { FILE *f; int i; int rec = 0; LIST *result = 0; regexp *re[ MAXINC ]; char buf[ 1024 ]; if( !( f = fopen( file, "r" ) ) ) return result; while( rec < MAXINC && hdrscan ) { re[rec++] = regcomp( hdrscan->string ); hdrscan = list_next( hdrscan ); } while( fgets( buf, sizeof( buf ), f ) ) { for( i = 0; i < rec; i++ ) if( regexec( re[i], buf ) && re[i]->startp[1] ) { /* Copy and terminate extracted string. */ char buf2[ MAXSYM ]; int l = re[i]->endp[1] - re[i]->startp[1]; memcpy( buf2, re[i]->startp[1], l ); buf2[ l ] = 0; result = list_new( result, buf2, 0 ); if( DEBUG_HEADER ) printf( "header found: %s\n", buf2 ); } } while( rec ) free( (char *)re[--rec] ); fclose( f ); return result; }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#8 | 9903 | Perforce staff |
Jam -dr now reports file/line numbers, at no small effort. New functionality documented in RELNOTES. p4transfer.py: Transferred from production |
||
#7 | 2501 | rmg |
Nascent jam work for header scan caching: new list_printq() for writing a list in a format suitable for being included by the Jambase, and move logic around in headers() to make room for eventual caching code. No functional change. === computer:1666: Change 38623 by seiwald@play-seiwald on 2002/12/09 16:22:59 |
||
#6 | 2493 | rmg |
Rewrite the past: update all jam's source with comments to reflect changes since about 2.3, very early 2001. Whitespace only change. === computer:1666: Change 37660 by seiwald@play-seiwald on 2002/11/06 22:41:35 Note: I regenerated jamgram.c on my linux 7.3 system prior to the submit, since patch was so unhappy trying to lay down the changes from Christopher's change. Presumably this is just due to different yacc/bison/whatever particulars on the system where Christopher made the changes originally. - rmg |
||
#5 | 2491 | rmg |
Some consting in jam to make it more compilable by C++ compilers. No functional change. === computer:1666: Change 37433 by perforce@perforce on 2002/10/30 16:08:51 Recreational const-ing of jam, for compilers that don't allow "string" to be passed as a non-const char *. This included a few places where we were modifying what could possibly have been read-only storage, oddly enough. No functional change. === computer:1666: Change 37602 by seiwald@play-seiwald on 2002/11/04 17:25:40 |
||
#4 | 2489 | rmg |
Jam tinkering: since all calls to list_new() must either newstr() or copystr() the added string, instead just pass a flag and let list_new() do the newstr/copystr. No functional change. === computer:1666: Change 37164 by seiwald@spice on 2002/10/22 01:21:58 |
||
#3 | 1497 | Perforce staff |
Support for invoking rules via variable expansion, i.e. "$(rule) targets : sources ;". Not yet documented. Documented in Jam.html (rmg change 1536) |
||
#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 |