[Top][All Lists]

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

Re: [Gnu-arch-users] Trying out the new escaping version...

From: Tom Lord
Subject: Re: [Gnu-arch-users] Trying out the new escaping version...
Date: Thu, 18 Mar 2004 08:26:55 -0800 (PST)

    > From: address@hidden

    > > In other words I expect this to work:
    > > $ mkdir foo\\bar
    > > $ tla add foo\\bar
    > > But it says:
    > > PANIC: Illegal escape sequence!

    > Thats by intention. It accepts "foo bar" and "foo\(sp)bar" but it will
    > barf on illegal escape sequences (guess why there is a panic() call).
    > For the one OS which accepts \ as path limiter the tla implementation
    > also accepts /.

    > In the rare case that you want filenames with backslashes you have to
    > escape them "tla add 'foo\\\\bar'" or "tla add `tla escape 'foo\\bar'`".

    > This is the correct and intended behaviour.


Please do not have commands expand their command line arguments.
Expansion is the job of whatever program _constructs_ the argv array,
not main().

Maybe it would help to think of it this way: internally to a program,
strings are kept in unescaped form.  Escaping is only added on output
and removed on input.   If a string is passed as an argument to a
function, it's normally passed unescaped.    There's nothing special
about `main()' -- it's arguments should be unescaped too.   The argv
to `main()' doesn't count as "input".

Consider, for example, a Python wrapper for tla.   It should approach
the quoting issue the same was as tla does itself:  unquoting strings
it reads from the output of tla commands, quoting strings in output
it wants to produce (if it wants that output to work like normal tla
output as opposed to, say, format a report for human consumption).

Such a wrapper should be able to invoke tla commands just by
constructing the appropriate argv.   It shouldn't be worrying about
which arguments to quote and which ones not to and what options to
provide to tweak which arguments are expanded.

"Callee-expands" is also a dubious approach because it effects only
tla.  It doesn't help with, for example, passing a filename to
`cat(1)'.  Should `cat(1)' be modified to do unescaping too?

One idea for an alternative is to write a command `pxapply':

  pxapply quoted-args ... '\(eof)' command normal args ...

which unquotes the quoted args and execs:

   command normal args .... unquoted args ...

and has an option:

  pxapply --fmt quoted-args ... '\(eof)' command normal args ...

which does roughly the same thing except that, in "normal args", an
argument of the form:

        @<n>            # <n> a non-negative decimal integer

is replaced by the Nth unquoted argument and:


is replaced by all of the unused quoted arguments.

The string '\(eof)' is useful as a separator between the quoted
arguments and the command line because we can guarantee that it is not
a validly quoted string.

The quoted arguments come first in the pxargs command line so that
there are no restrictions on the other arguments to COMMAND.


reply via email to

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