diff options
author | Vladimir Glazounov <vg@openoffice.org> | 2006-09-25 08:39:30 +0000 |
---|---|---|
committer | Vladimir Glazounov <vg@openoffice.org> | 2006-09-25 08:39:30 +0000 |
commit | aa74c69eb8c0b85f7a4d50edc48625da753fb090 (patch) | |
tree | 7d690ca549df5e5dca51397d7819ce7c83e34ba4 | |
parent | INTEGRATION: CWS dmake46 (1.4.2); FILE MERGED (diff) | |
download | core-aa74c69eb8c0b85f7a4d50edc48625da753fb090.tar.gz core-aa74c69eb8c0b85f7a4d50edc48625da753fb090.zip |
INTEGRATION: CWS dmake46 (1.5.8); FILE MERGED
2006/09/21 16:24:10 vq 1.5.8.4: #i69743# Optimize expand.c:Apply_edit().
2006/08/15 18:11:35 vq 1.5.8.3: #i44961# Reject single letter macros with (, {, ), } and : .
2006/08/15 15:07:05 vq 1.5.8.2: #i44961# Throw error if inclosed macro brackets are encountered.
2006/07/17 03:10:57 vq 1.5.8.1: #i67166# Make dmake issue a warning if a previously unset macro (i.e. it is
assumed to be empty) is used and later set to a different value.
-rw-r--r-- | dmake/expand.c | 49 |
1 files changed, 32 insertions, 17 deletions
diff --git a/dmake/expand.c b/dmake/expand.c index ccdf7bfc7d0c..08f6a3736bd5 100644 --- a/dmake/expand.c +++ b/dmake/expand.c @@ -1,6 +1,6 @@ /* $RCSfile: expand.c,v $ --- $Revision: 1.5 $ --- last change: $Author: hr $ $Date: 2006-04-20 11:59:48 $ +-- $Revision: 1.6 $ +-- last change: $Author: vg $ $Date: 2006-09-25 09:39:30 $ -- -- SYNOPSIS -- Macro expansion code. @@ -183,11 +183,13 @@ int anchor; /* if TRUE anchor */ DB_ENTER( "Apply_edit" ); - if( !*pat ) DB_RETURN( src ); /* do nothing if pat is NULL */ + /* do nothing if pat is NULL or pat and subst are equal */ + if( !*pat || !strcmp(pat,subst) ) DB_RETURN( src ); DB_PRINT( "mod", ("Source str: [%s]", src) ); DB_PRINT( "mod", ("Replacing [%s], with [%s]", pat, subst) ); + /* FIXME: This routine is used frequently and has room for optimizations */ s = src; l = strlen( pat ); if( (p = DmStrStr( s, pat )) != NIL(char) ) { @@ -672,8 +674,11 @@ int doexpand; /* If TRUE enables macro expansion */ if( lev == 1 && !fflag && doexpand ) { done = TRUE; mflag = 1; - } else /* must be $: */ - done = !lev; + } + else if( !lev ) /* must be $: */ + Fatal( "Syntax error in macro [$%s]. A colon [:] cannot be a macro name.\n", start ); + + /* continue if a colon is found but lev > 1 */ break; case '\n': /* Not possible because of the @@ -698,20 +703,23 @@ int doexpand; /* If TRUE enables macro expansion */ case '\0': /* check for null */ *ps = s; done = TRUE; - if( lev ) { - bflag = 0; - s = start; + if( lev ) { /* catch $( or ${ without closing bracket */ + Fatal( "Syntax error in macro [$%s]. The closing bracket [%c] is missing.\n", start, edelim ); } else Fatal( "DEBUG: This cannot occur! [%s].\n", start ); break; case ')': /* close macro brace */ case '}': - if( *s == edelim && lev ) --lev; + if( !lev ) /* A closing bracket without an .. */ + Fatal("Syntax error in macro [$%s]. Closing bracket [%c] cannot be a macro name.\n", start, *s ); + else if( *s == edelim ) --lev; /*FALLTHRU*/ - default: /* Done when lev == 0 */ - done = !lev; + default: /* Done when lev == 0. This means either no */ + done = !lev; /* opening bracket (single letter macro) or */ + /* a fully enclosed $(..) or ${..} macro */ + /* was found. */ } s++; } @@ -763,14 +771,21 @@ int doexpand; /* If TRUE enables macro expansion */ else result = DmStrDup( "" ); - /* - * Mark macros as used only if we are not expanding them for - * the purpose of a .IF test, so we can warn about redef after use*/ - - if( !If_expand ) hp->ht_flag |= M_USED; } - else + else { + /* The use of an undefined macro implicitly defines it but + * leaves its value to NIL(char). */ + hp = Def_macro( macro_name, NIL(char), M_EXPANDED ); + /* Setting M_INIT assures that this macro is treated unset like + * default internal macros. (Necessary for *= and *:=) */ + hp->ht_flag |= M_INIT; + result = DmStrDup( "" ); + } + /* Mark macros as used only if we are not expanding them for + * the purpose of a .IF test, so we can warn about redef after use*/ + if( !If_expand ) hp->ht_flag |= M_USED; + } if( mflag ) { |