Parameters with single and double quotes

Joel Shprentz <[email protected]> Sun, 15 Jun 2003 00:51:09 -0400
Newsgroups gmane.comp.sysutils.ark.devel
Message-ID <[email protected]>
Summary:  I'm doomed.

Synopsis:  Ark loses double quotes when defining this value of parameter 
make_args:

   CC=/our/bin/gcc CCARGS='-DDEF_CONFIG_DIR=\"/usr/local/etc/postfix\" 
-DDEF_DAEMON_DIR=\"/usr/local/libexec/postfix\"'

Suspect:  The metaQuote function in ARK/arkbase/ark/utils.py

Background:  (Stop here if you've heard this already.)

I'm working on packages for Wietse Venema's mailer, Postfix 
(www.postfix.org), and its configuration files.  Postfix does not use the 
typical ./configure command for configuration.  Instead, "make makefiles" 
invokes a series of sed scripts to build Makefiles with default or 
overridden parameters.  With Ark, of course, we override everything.

To build with the C compiler of our choice, we specify the usual:

   <param name="cc">@proxy-host:CC@</param>

Several directories and file paths are compiled into Postfix.  Two examples 
are:

   <param name="config_dir">/usr/local/etc/postfix</param>
   <param name="daemon_dir">/usr/local/libexec/postfix</param>

Postfix's INSTALL describes the slightly tricky format for specifying these 
directories:

   In order to build with non-default settings, for example, with a
   configuration directory other than /etc/postfix, use:

       % make makefiles CCARGS='-DDEF_CONFIG_DIR=\"/some/where\"'
       % make

   Be sure to get the quotes right. These details matter a lot.

Combining the directory parameters into a single ccargs parameter should be 
no problem (two of nine directories and paths shown here):

   <param name="ccargs">
     -DDEF_CONFIG_DIR=\"@param:config_dir@\"
     -DDEF_DAEMON_DIR=\"@param:daemon_dir@\"
   </param>

Put everything together to create make_args:

   <param name="make_args">CC=@param:cc@ CCARGS='@param:ccargs@'</param>

This does not work.  The double quotes around the directories and paths 
disappear.

It appears that the expandParams method of ArkRunnable in 
ARK/arkbase/ark/thing.py calls the metaQuote function in 
ARK/arkbase/ark/utils.py, which tries to handle quotes and other special 
characters.  When a string contains single quotes, metaQuote wraps the 
string in double quotes, but does not escape any embedded double quotes.  I 
think this could be fixed by adding another string.replace around line 980 
in utils.py (and renumbering the subsequent intermediate strings):

       # use a double-quote; quote all the weird chars:
       str1 = string.replace(str ,'\\','\\\\')
       str2 = string.replace(str1,'$', '\\$')
+     str3 = string.replace(str2,'"', '\\"')

Deeper Background:  What is Postfix doing?

As mentioned above, "make makefiles" invokes a series of sed scripts to 
build Makefiles.  The sed scripts combine the CC and CCARGS parameters into 
a single definition of CC that appears in all the Makefiles.  Something in 
that process consumes the backslashes, so the resulting definition looks 
like this:

   CC=/our/bin/gcc -DDEF_CONFIG_DIR="/usr/local/etc/postfix" 
-DDEF_DAEMON_DIR="/usr/local/libexec/postfix"

Q: Why must quotes surround the directories and paths?
A: Defined symbols like DEF_CONFIG_DIR expand to literal strings in the C code.

Maybe I'm not doomed.

--

Joel Shprentz
National Imagery and Mapping Agency
Mailstop N-17
Washington Navy Yard, Building 213
1200 First Street, SE
Washington, DC 20303-0001

202-685-3534 




-------------------------------------------------------
This SF.NET email is sponsored by: eBay
Great deals on office technology -- on eBay now! Click here:
http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5