Kaydet (Commit) bf1dc2ec authored tarafından Ivo Hinkelmann's avatar Ivo Hinkelmann

INTEGRATION: CWS dmake411 (1.10.6); FILE MERGED

2007/08/28 18:28:23 vq 1.10.6.3: #i64234# Fix $(mktmp ..) handling of leading spaces.
2007/08/05 21:10:13 vq 1.10.6.2: #i50092# Enhance $(shell,expand .. ) parsing. Add testcase.
2007/07/24 23:00:27 vq 1.10.6.1: #i78776# New function macro $(normpath[,para] list) to normalise the
elements of list and a macro extension $(macro_name:n) to normalise
the content of macro_name. The normalization is done token-wise and
quotes are preserved.
On cygwin the result honors the setting of .WINPATH to determine the
output format.  If the optional parameter para is given in the
$(normpath ...) case its expanded value is used to override the
.WINPATH setting for the output of the function macro.
üst 71534fc7
/* $RCSfile: function.c,v $ /* $RCSfile: function.c,v $
-- $Revision: 1.10 $ -- $Revision: 1.11 $
-- last change: $Author: vg $ $Date: 2007-01-18 09:30:04 $ -- last change: $Author: ihi $ $Date: 2007-10-15 15:39:11 $
-- --
-- SYNOPSIS -- SYNOPSIS
-- GNU style functions for dmake. -- GNU style functions for dmake.
...@@ -35,7 +35,7 @@ static char *_exec_iseq ANSI((char *, char *, char *, int)); ...@@ -35,7 +35,7 @@ static char *_exec_iseq ANSI((char *, char *, char *, int));
static char *_exec_sort ANSI((char *)); static char *_exec_sort ANSI((char *));
static char *_exec_echo ANSI((char *)); static char *_exec_echo ANSI((char *));
static char *_exec_uniq ANSI((char *)); static char *_exec_uniq ANSI((char *));
static char *_exec_shell ANSI((char *, char *)); static char *_exec_shell ANSI((char *, int));
static char *_exec_call ANSI((char *, char *)); static char *_exec_call ANSI((char *, char *));
static char *_exec_assign ANSI((char *)); static char *_exec_assign ANSI((char *));
static char *_exec_foreach ANSI((char *, char *, char *)); static char *_exec_foreach ANSI((char *, char *, char *));
...@@ -151,6 +151,30 @@ char *buf; ...@@ -151,6 +151,30 @@ char *buf;
} }
else if (strncmp(fname,"not",3) == 0 ) else if (strncmp(fname,"not",3) == 0 )
res = _exec_not(args); res = _exec_not(args);
else if (strncmp(fname,"normpath",8) == 0 ) {
char *eargs = Expand(args);
if( mod_count == 0 ) {
res = exec_normpath(eargs);
}
else if( mod_count == 1 ) {
char *para = Expand(mod1);
int tmpUseWinpath = UseWinpath;
if( !*para || strcmp(para, "\"\"") == 0 ) {
UseWinpath = FALSE;
} else {
UseWinpath = TRUE;
}
res = exec_normpath(eargs);
UseWinpath = tmpUseWinpath;
FREE(para);
}
else
Fatal( "One or no comma-seperated arguments expected in [%s].\n", buf );
FREE(eargs);
}
else else
res = _exec_call(fname,args); res = _exec_call(fname,args);
break; break;
...@@ -178,7 +202,19 @@ char *buf; ...@@ -178,7 +202,19 @@ char *buf;
if(strncmp(fname,"sort",4) == 0) if(strncmp(fname,"sort",4) == 0)
res = _exec_sort(args); res = _exec_sort(args);
else if(strncmp(fname,"shell",5)==0) else if(strncmp(fname,"shell",5)==0)
res = _exec_shell(args,mod1); if( mod_count == 0 ) {
res = _exec_shell(args, FALSE);
}
else if( mod_count == 1 ) {
char *emod = Expand(mod1);
if(strncmp(emod,"expand",7)==0)
res = _exec_shell(args, TRUE);
else
Fatal( "Unknown argument [%s] to shell in [%s].\n", emod, buf );
FREE(emod);
}
else
Fatal( "One or no comma-seperated arguments expected in [%s].\n", buf );
else if(strncmp(fname,"strip",5)==0) else if(strncmp(fname,"strip",5)==0)
res = Tokenize(Expand(args)," ",'t',TRUE); res = Tokenize(Expand(args)," ",'t',TRUE);
else if(strncmp(fname,"subst",5)==0) { else if(strncmp(fname,"subst",5)==0) {
...@@ -297,7 +333,6 @@ char *file; ...@@ -297,7 +333,6 @@ char *file;
char *text; char *text;
char *data; char *data;
{ {
register char *p;
char *tmpname; char *tmpname;
char *name; char *name;
FILE *tmpfile = NIL(FILE); FILE *tmpfile = NIL(FILE);
...@@ -309,13 +344,7 @@ char *data; ...@@ -309,13 +344,7 @@ char *data;
name = Current_target ? Current_target->CE_NAME:"makefile text"; name = Current_target ? Current_target->CE_NAME:"makefile text";
if( file && *file ) { if( file && *file ) {
/* This call to Get_temp sets TMPFILE for subsequent expansion of file. /* Expand the file parameter to mktmp if present. */
* The contents file variable passed may include TMPFILE to be expanded. */
/* Using TMPFILE as an argument to mktmp is no longer supported because it is not
* safe to create a random filename and assume the file does not exist. Howver,
* we still allow Expand() to do its job for fixed filenames */
/* char *newtmp;
* Get_temp( &newtmp, FALSE ); FREE(newtmp); */
tmpname = Expand(file); tmpname = Expand(file);
if( *tmpname ) { if( *tmpname ) {
...@@ -336,6 +365,9 @@ char *data; ...@@ -336,6 +365,9 @@ char *data;
Def_macro("TMPFILE", tmpname, M_EXPANDED|M_MULTI); Def_macro("TMPFILE", tmpname, M_EXPANDED|M_MULTI);
Link_temp( Current_target, tmpfile, tmpname ); Link_temp( Current_target, tmpfile, tmpname );
/* Don't free tmpname if it is used. It is stored in a FILELIST
* member in Link_temp(). */
} }
else else
FREE(tmpname); FREE(tmpname);
...@@ -344,16 +376,12 @@ char *data; ...@@ -344,16 +376,12 @@ char *data;
if( !tmpfile ) if( !tmpfile )
tmpfile = Start_temp( "", Current_target, &tmpname ); tmpfile = Start_temp( "", Current_target, &tmpname );
/* If the text parameter is given return its expanded value
* instead of the used filename. */
if( !text || !*text ) text = tmpname; if( !text || !*text ) text = tmpname;
data = Expand(DmStrSpn(data, " \t\n"));
for(p=strchr(data,'\n'); p; p=strchr(p,'\n')) { data = Expand(data);
char *q = DmStrSpn(++p," \t");
strcpy(p,q);
}
/* do not map escape sequences while writing a tmpfile */
/* Append_line( data, FALSE, tmpfile, name, FALSE, TRUE ); */
Append_line( data, TRUE, tmpfile, name, FALSE, FALSE ); Append_line( data, TRUE, tmpfile, name, FALSE, FALSE );
Close_temp( Current_target, tmpfile ); Close_temp( Current_target, tmpfile );
FREE(data); FREE(data);
...@@ -500,11 +528,12 @@ char *data; ...@@ -500,11 +528,12 @@ char *data;
static char * static char *
_exec_shell( data, mod1 )/* _exec_shell( data, expand )/*
=========================== =============================
Capture the stdout of an execuded command. */ Capture the stdout of an execuded command.
If expand is TRUE expand the result. */
char *data; char *data;
char *mod1; int expand;
{ {
extern char *tempnam(); extern char *tempnam();
int bsize; int bsize;
...@@ -608,10 +637,11 @@ char *mod1; ...@@ -608,10 +637,11 @@ char *mod1;
stdout_redir = old_stdout_redir; stdout_redir = old_stdout_redir;
if ( mod1 ) { if ( expand ) {
mod1 = Expand(res); char *exp_res;
exp_res = Expand(res);
FREE(res); FREE(res);
res = mod1; res = exp_res;
} }
return(res); return(res);
...@@ -657,3 +687,32 @@ char *args; ...@@ -657,3 +687,32 @@ char *args;
FREE(p); FREE(p);
return(res ? DmStrDup("t") : DmStrDup("")); return(res ? DmStrDup("t") : DmStrDup(""));
} }
char *
exec_normpath( args )/*
=======================
Normalize token-wise. The normalised filenames are returned in a new
string, the original string is not freed. Quoted tokens remain quoted
after the normalizaton. */
char *args;
{
TKSTR str;
char *s, *res;
/* This honors .WINPATH . */
SET_TOKEN( &str, args );
res = NIL(char);
while( *(s = Get_token( &str, "", FALSE )) != '\0' ) {
if(str.tk_quote == 0) {
/* Add leading quote. */
res = DmStrApp(res, "\"");
res = DmStrJoin(res, DO_WINPATH(normalize_path(s)), -1, TRUE);
/* Append the trailing quote. */
res = DmStrJoin(res, "\"", 1, TRUE);
} else {
res = DmStrApp(res, DO_WINPATH(normalize_path(s)));
}
}
return res;
}
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