[Cook] Escaping characters for the shell command line

Pendergraft, Jerry JPendergraft at sjm.com
Tue Jun 14 04:53:17 EST 2005


The single quote is handy to get a double quote character in the output.
As to the unsplit. Note that [unsplit ..] is one of the arguments to the catenate. The catenate does not operate on the content.
And yes the output must have the " " in there because the __FILE__ type items wind up quoted by the preprocessor (at least most pre-processors). That is why I suggested generating the content rather than using those. It would make it much simpler.
You can get __DATE__ and __TIME__ by [collect date ...]
And you have the file name within the recipe as %.cpp  (or whatever your source recipe uses)

-----Original Message-----
From: cook-users-bounces+jpendergraft=sjm.com at auug.org.au on behalf of Henderson, Michael D
Sent: Mon 13-Jun-05 11:44
To: Cook Users List (E-mail)
Subject: RE: [Cook] Escaping characters for the shell command line
 
Jerry, thanks for the reply.

It looks like you're using single quotes around the part after the equal
signs. That's smarter than what I did, since it'll remove all of those
\\\" from it.

I don't understand the use of unsplit, though. It seems to be producing
the equivalent to

             ' " __FILE__ " " __DATE__ " " __TIME__'

after you apply the catenate. What's the reasoning there? Is unsplit a
good idiom in this case?

Also, Jeff had suggested using the quote function. I went through the
manuals but there's not much on it. I'll keep looking at that.

Thanks again,
Mike

-----Original Message-----
Sent: Friday, June 10, 2005 11:28 PM
Subject: Re: [Cook] Escaping characters for the shell command line

Many times it is easier to use some cook functions to create such
strings.
The following pretty much does what you want but for a couple things.
I did not include the newline characters because they result in a
compiler
warning about multiline string constants. Also using __FILE__ etc must
rely on pre-processor concatination. I believe it might be easier to
construct that data within the cook recipe and build the whole literal
string.
-----
/* THE VERSION STAMP FOR A PARTICULAR BUILD */
/* */
set nosilent;


Project = foo;
Ver = 0.0.0;


cpp_flags = [catenate -DPKG_IDENT\=
             '\'"'
               "@(#)" [Project] - [Ver]
             ' "'
               [unsplit " "  __FILE__ '" "'  __DATE__ '" "' __TIME__]
             '\''
             ];

all : ident.o set default;

%.o : %.cpp  [__FILE__] set default
{
    function print "gen" [target] "due to" [need];

    g++ [cpp_flags] -o [target] -c %.cpp;
}

-- 
Jerry Pendergraft
jerry.pendergraft at endocardial.com
St. Jude Medical                         voice: 651-523-6935
1350 Energy Lane, Suite 110                fax: 651-644-7897
St Paul, MN 55108-5254                  mobile: 651-491-0163

On Thu, 9 Jun 2005, Henderson, Michael D wrote:

> Okay, this is driving me nuts. Is there an easy way to escape
arguments for the command line? I'm trying to drive the ident string for
my files, but trying to figure out how to escape this string is driving
me nuts.
> 
>   Project = foo;
>   Ver = 0.0.0;
>   cpp_flags = -DPKG_IDENT\=\"\\\"\\n@(#)[Project]-[Ver] \\\" __FILE__
\\\"  \\\" __DATE__ \\\" \\\" __TIME__\\\"\\n\\\"\";
> 
> It took me about 15 minutes to plug through this, using trial and
error. Is there a simpler way to do this?
> 
> If you want a sample ident.cpp, try a file with just the following in
it
> 
>   static const char *myIdent = PKG_IDENT;
> 
> Thanks,
> Mike
_______________________________________________
Cook-users mailing list
Cook-users at auug.org.au
http://www.auug.org.au/mailman/listinfo/cook-users




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.auug.org.au/pipermail/cook-users/attachments/20050613/e1b535a3/attachment.htm>


More information about the Cook-users mailing list