From 1859f9fb441cdace376b7b33c829fe7cb243a488 Mon Sep 17 00:00:00 2001 From: Rene Rivera Date: Sun, 16 Sep 2007 21:35:19 +0000 Subject: [PATCH] Implement @() expansion during parse phase. (fixes #721) [SVN r39330] --- src/engine/expand.c | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/src/engine/expand.c b/src/engine/expand.c index 09ff1fc4b..082efc7fe 100644 --- a/src/engine/expand.c +++ b/src/engine/expand.c @@ -90,19 +90,56 @@ var_expand( /* This gets alot of cases: $(<) and $(>) */ - if( in[0] == '$' && in[1] == '(' && in[3] == ')' && !in[4] ) + if( in[0] == '$' && in[1] == '(' && in[3] == ')' && in[4] == '\0' ) { switch( in[2] ) { - case '1': case '<': return list_copy( l, lol_get( lol, 0 ) ); - case '2': case '>': return list_copy( l, lol_get( lol, 1 ) ); + + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + return list_copy( l, lol_get( lol, in[2]-'1' ) ); } } + + /* Expand @() files, to single item plus accompanying file. */ + + if ( in[0] == '@' && in[1] == '(' && *(end-1) == ')' ) + { + /* We try the expansion until it fits within the propspective output buffer. */ + char * at_buf = 0; + int at_size = MAXJPATH; + int at_len = 0; + do + { + BJAM_FREE(at_buf); + at_buf = (char*)BJAM_MALLOC_ATOMIC(at_size + 1); + at_len = var_string( in, at_buf, at_size, lol ); + at_size *= 2; + } while ( at_len < 0 && at_len < INT_MAX / 2 ); + /* Return the result as a single item list. */ + if ( at_len > 0 ) + { + LIST * r; + string_copy( buf, at_buf ); + r = list_new( l, newstr( buf->value) ); + string_free( buf ); + BJAM_FREE(at_buf); + return r; + } + BJAM_FREE(at_buf); + } /* Just try simple copy of in to out. */