summaryrefslogtreecommitdiff
path: root/dmake/function.c
diff options
context:
space:
mode:
authorIvo Hinkelmann <ihi@openoffice.org>2007-10-15 14:39:11 +0000
committerIvo Hinkelmann <ihi@openoffice.org>2007-10-15 14:39:11 +0000
commitbf1dc2eceb0fbe7cd9be6e57fff65d8ce94cea8f (patch)
treea988c216f333e30bf58251ef5deed9a3a3530e38 /dmake/function.c
parent71534fc7c42cb4f88ddc7cb6c7ca84df611e6a71 (diff)
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.
Diffstat (limited to 'dmake/function.c')
-rw-r--r--dmake/function.c111
1 files changed, 85 insertions, 26 deletions
diff --git a/dmake/function.c b/dmake/function.c
index e369161fd29e..f764026eb595 100644
--- a/dmake/function.c
+++ b/dmake/function.c
@@ -1,6 +1,6 @@
/* $RCSfile: function.c,v $
--- $Revision: 1.10 $
--- last change: $Author: vg $ $Date: 2007-01-18 09:30:04 $
+-- $Revision: 1.11 $
+-- last change: $Author: ihi $ $Date: 2007-10-15 15:39:11 $
--
-- SYNOPSIS
-- GNU style functions for dmake.
@@ -35,7 +35,7 @@ static char *_exec_iseq ANSI((char *, char *, char *, int));
static char *_exec_sort ANSI((char *));
static char *_exec_echo 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_assign ANSI((char *));
static char *_exec_foreach ANSI((char *, char *, char *));
@@ -151,6 +151,30 @@ char *buf;
}
else if (strncmp(fname,"not",3) == 0 )
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
res = _exec_call(fname,args);
break;
@@ -178,7 +202,19 @@ char *buf;
if(strncmp(fname,"sort",4) == 0)
res = _exec_sort(args);
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)
res = Tokenize(Expand(args)," ",'t',TRUE);
else if(strncmp(fname,"subst",5)==0) {
@@ -297,7 +333,6 @@ char *file;
char *text;
char *data;
{
- register char *p;
char *tmpname;
char *name;
FILE *tmpfile = NIL(FILE);
@@ -309,13 +344,7 @@ char *data;
name = Current_target ? Current_target->CE_NAME:"makefile text";
if( file && *file ) {
- /* This call to Get_temp sets TMPFILE for subsequent expansion of file.
- * 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); */
+ /* Expand the file parameter to mktmp if present. */
tmpname = Expand(file);
if( *tmpname ) {
@@ -336,6 +365,9 @@ char *data;
Def_macro("TMPFILE", tmpname, M_EXPANDED|M_MULTI);
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
FREE(tmpname);
@@ -344,16 +376,12 @@ char *data;
if( !tmpfile )
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;
- data = Expand(DmStrSpn(data, " \t\n"));
- for(p=strchr(data,'\n'); p; p=strchr(p,'\n')) {
- char *q = DmStrSpn(++p," \t");
- strcpy(p,q);
- }
+ data = Expand(data);
-/* 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 );
Close_temp( Current_target, tmpfile );
FREE(data);
@@ -500,11 +528,12 @@ char *data;
static char *
-_exec_shell( data, mod1 )/*
-===========================
- Capture the stdout of an execuded command. */
+_exec_shell( data, expand )/*
+=============================
+ Capture the stdout of an execuded command.
+ If expand is TRUE expand the result. */
char *data;
-char *mod1;
+int expand;
{
extern char *tempnam();
int bsize;
@@ -608,10 +637,11 @@ char *mod1;
stdout_redir = old_stdout_redir;
- if ( mod1 ) {
- mod1 = Expand(res);
+ if ( expand ) {
+ char *exp_res;
+ exp_res = Expand(res);
FREE(res);
- res = mod1;
+ res = exp_res;
}
return(res);
@@ -657,3 +687,32 @@ char *args;
FREE(p);
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;
+}