bug-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 'withfile' function implementation


From: Paul Smith
Subject: Re: 'withfile' function implementation
Date: Mon, 16 Jan 2012 08:14:44 -0500

On Thu, 2011-12-15 at 15:13 -0800, Lawrence Ibarria wrote:
> This is a rather simple path that implements a very simplified version
> of what Tim suggested in his message of Sept 25th
> (https://lists.gnu.org/archive/html/bug-make/2011-09/msg00044.html ).
> 
> Paul, what do you think? I’d rather not try to do everything, just
> focus on one thing. I am not sure how much safety checks play a role
> inside make. 

I was looking at this (and https://savannah.gnu.org/bugs/index.php?35147)

I'm still not in love with it.  I have the following concerns:

     1. I still think the "a", "w" mode thing is clunky.
     2. Unclear what to do about newlines.  The code doesn't add any but
        getting a newline into a make variable is tricky.
     3. The suggested patch is really only about 20% of the work: we
        also need documentation, regression tests, etc.  Although I
        guess doing this before the interface is locked down makes extra
        work (but not for me! :-)).

Here's an alternative suggestion, modeled more on the shell's file
redirection rather than the C runtime's stdio:

One new function, named "file" (?).  The function takes one or two
arguments.

The first argument is a filename, preceded by a token that specifies how
the file is to be treated, with optional whitespace between them.  The
tokens are:

'>' : open the file with mode "w" (truncate) and write the second
argument to the file, plus a newline.  If no second argument is given,
nothing is written (the file will be empty).  The expansion of the
function is the empty string.

'>>' : Open the file with mode "a" (append) and write the second
argument to the file, plus a newline.  If no second argument is given,
nothing is written (if the file didn't exist it will be created but
empty; if the file did exist it will be unchanged).  The expansion of
the function is the empty string.

'<' : Open the file with mode "r" and expand to the full contents of the
file.  No conversion is done (the resulting text may have embedded
newlines).  Use $(strip ...) to remove them if desired.


So, some examples might be:

        $(file >t.out,this is the first line)
        $(file >>t.out,this is the second line)
        $(file >> t.out,this is the third line)
        FILE := $(file < t.out)

Do people think this would be useable?

I thought about defining three functions ">", ">>", and "<", rather than
"file", but this would require a space between the "function name" and
the file name; if you forgot the space (as you can do in the shell) then
make would be looking to expand a variable/function named ">t.out"
rather than the function ">" with the first argument of "t.out".  I just
wonder if it would create more issues than it's worth to be cute like
that.  Still, it's an option.

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <address@hidden>          Find some GNU make tips at:
 http://www.gnu.org                      http://make.mad-scientist.net
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist




reply via email to

[Prev in Thread] Current Thread [Next in Thread]