Kaydet (Commit) aa74c69e authored tarafından Vladimir Glazounov's avatar Vladimir Glazounov

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.
üst c5ce2766
/* $RCSfile: expand.c,v $ /* $RCSfile: expand.c,v $
-- $Revision: 1.5 $ -- $Revision: 1.6 $
-- last change: $Author: hr $ $Date: 2006-04-20 11:59:48 $ -- last change: $Author: vg $ $Date: 2006-09-25 09:39:30 $
-- --
-- SYNOPSIS -- SYNOPSIS
-- Macro expansion code. -- Macro expansion code.
...@@ -183,11 +183,13 @@ int anchor; /* if TRUE anchor */ ...@@ -183,11 +183,13 @@ int anchor; /* if TRUE anchor */
DB_ENTER( "Apply_edit" ); 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", ("Source str: [%s]", src) );
DB_PRINT( "mod", ("Replacing [%s], with [%s]", pat, subst) ); DB_PRINT( "mod", ("Replacing [%s], with [%s]", pat, subst) );
/* FIXME: This routine is used frequently and has room for optimizations */
s = src; s = src;
l = strlen( pat ); l = strlen( pat );
if( (p = DmStrStr( s, pat )) != NIL(char) ) { if( (p = DmStrStr( s, pat )) != NIL(char) ) {
...@@ -672,8 +674,11 @@ int doexpand; /* If TRUE enables macro expansion */ ...@@ -672,8 +674,11 @@ int doexpand; /* If TRUE enables macro expansion */
if( lev == 1 && !fflag && doexpand ) { if( lev == 1 && !fflag && doexpand ) {
done = TRUE; done = TRUE;
mflag = 1; 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; break;
case '\n': /* Not possible because of the case '\n': /* Not possible because of the
...@@ -698,20 +703,23 @@ int doexpand; /* If TRUE enables macro expansion */ ...@@ -698,20 +703,23 @@ int doexpand; /* If TRUE enables macro expansion */
case '\0': /* check for null */ case '\0': /* check for null */
*ps = s; *ps = s;
done = TRUE; done = TRUE;
if( lev ) { if( lev ) { /* catch $( or ${ without closing bracket */
bflag = 0; Fatal( "Syntax error in macro [$%s]. The closing bracket [%c] is missing.\n", start, edelim );
s = start;
} else } else
Fatal( "DEBUG: This cannot occur! [%s].\n", start ); Fatal( "DEBUG: This cannot occur! [%s].\n", start );
break; break;
case ')': /* close macro brace */ case ')': /* close macro brace */
case '}': 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*/ /*FALLTHRU*/
default: /* Done when lev == 0 */ default: /* Done when lev == 0. This means either no */
done = !lev; done = !lev; /* opening bracket (single letter macro) or */
/* a fully enclosed $(..) or ${..} macro */
/* was found. */
} }
s++; s++;
} }
...@@ -763,14 +771,21 @@ int doexpand; /* If TRUE enables macro expansion */ ...@@ -763,14 +771,21 @@ int doexpand; /* If TRUE enables macro expansion */
else else
result = DmStrDup( "" ); 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( "" ); 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 ) { if( mflag ) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment