Author: njn
Date: 2007-11-23 22:37:35 +0000 (Fri, 23 Nov 2007)
New Revision: 7204

Log:
Tweak VG_(expand_file_name), as per Josef's suggestions.

Modified:
   trunk/coregrind/m_options.c
   trunk/include/pub_tool_options.h


Modified: trunk/coregrind/m_options.c
===================================================================
--- trunk/coregrind/m_options.c 2007-11-23 01:42:10 UTC (rev 7203)
+++ trunk/coregrind/m_options.c 2007-11-23 22:37:35 UTC (rev 7204)
@@ -144,11 +144,18 @@
       goto bad;
    }
 
+   // If 'format' starts with a '/', do not prefix with startup dir.
+   if (format[0] != '/') {
+      j += VG_(strlen)(base_dir);
+   }
+
    // The 10 is slop, it should be enough in most cases.
-   j = VG_(strlen)(base_dir);
    len = j + VG_(strlen)(format) + 10;
    out = VG_(malloc)( len );
-   VG_(strcpy)(out, base_dir);
+   if (format[0] != '/') {
+      VG_(strcpy)(out, base_dir);
+      out[j++] = '/';
+   }
 
 #define ENSURE_THIS_MUCH_SPACE(x) \
    if (j + x >= len) { \
@@ -156,7 +163,6 @@
       out = VG_(realloc)(out, len); \
    }
 
-   out[j++] = '/';
    while (format[i]) {
       if (format[i] != '%') {
          ENSURE_THIS_MUCH_SPACE(1);
@@ -178,35 +184,44 @@
             j += VG_(sprintf)(&out[j], "%d", pid);
             i++;
          } 
-         else if ('q' == format[i] && '{' == format[i+1]) {
-            // Get the env var name, print its contents.
-            Char* qualname;
-            Char* qual;
-            i += 2;
-            qualname = &format[i];
-            while (True) {
-               if (0 == format[i]) {
-                  VG_(message)(Vg_UserMsg, "%s: malformed %%q specifier",
-                     option_name);
-                  goto bad;
-               } else if ('}' == format[i]) {
-                  // Temporarily replace the '}' with NUL to extract var name.
-                  format[i] = 0;
-                  qual = VG_(getenv)(qualname);
-                  if (NULL == qual) {
-                     VG_(message)(Vg_UserMsg,
-                        "%s: environment variable %s is not set",
-                        option_name, qualname);
+         else if ('q' == format[i]) {
+            i++;
+            if ('{' == format[i]) {
+               // Get the env var name, print its contents.
+               Char* qualname;
+               Char* qual;
+               i++;
+               qualname = &format[i];
+               while (True) {
+                  if (0 == format[i]) {
+                     VG_(message)(Vg_UserMsg, "%s: malformed %%q specifier",
+                        option_name);
                      goto bad;
+                  } else if ('}' == format[i]) {
+                     // Temporarily replace the '}' with NUL to extract var
+                     // name.
+                     format[i] = 0;
+                     qual = VG_(getenv)(qualname);
+                     if (NULL == qual) {
+                        VG_(message)(Vg_UserMsg,
+                           "%s: environment variable %s is not set",
+                           option_name, qualname);
+                        format[i] = '}';  // Put the '}' back.
+                        goto bad;
+                     }
+                     format[i] = '}';     // Put the '}' back.
+                     i++;
+                     break;
                   }
-                  format[i] = '}';     // Put the '}' back.
                   i++;
-                  break;
                }
-               i++;
+               ENSURE_THIS_MUCH_SPACE(VG_(strlen)(qual));
+               j += VG_(sprintf)(&out[j], "%s", qual);
+            } else {
+               VG_(message)(Vg_UserMsg,
+                  "%s: expected '{' after '%%q'", option_name);
+               goto bad;
             }
-            ENSURE_THIS_MUCH_SPACE(VG_(strlen)(qual));
-            j += VG_(sprintf)(&out[j], "%s", qual);
          } 
          else {
             // Something else, abort.

Modified: trunk/include/pub_tool_options.h
===================================================================
--- trunk/include/pub_tool_options.h    2007-11-23 01:42:10 UTC (rev 7203)
+++ trunk/include/pub_tool_options.h    2007-11-23 22:37:35 UTC (rev 7204)
@@ -130,6 +130,9 @@
      isn't set, we abort.  If the "{QUAL}" part is malformed, we abort.
    - "%%" is replaced with "%".
    Anything else after '%' causes an abort.
+   If the format specifies a relative file name, it's put in the program's
+   initial working directory.  If it specifies an absolute file name (ie.
+   starts with '/') then it is put there.
 */
 extern Char* VG_(expand_file_name)(Char* option_name, Char* format);
 


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Valgrind-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/valgrind-developers

Reply via email to