Tue 20 Dec 2005 01:14:16 PM UTC, comment #5:
Your patch is not quite right:
+boolean
+looks_like_expression(const char *arg)
+{
+ switch (arg[0])
+ {
+ case '-':
+ if (arg[1]) /* "-foo" is an expression. */
+ return true;
+ else
+ return false; /* Just "-" is a filename. */
+ break;
Hmm, I thought that "-" starts with a '-', so it should be treated as an invalid option, but I guess you are okay in saying that the POSIX wording of "starts with" implies improper substring, therefore "-" is a filename since it is an exact match rather than a prefix.
Which raises the question - if you treat "-" as a filename, is it the file ./-, or is it shorthand for stdin (on systems where stdin can be redirected from a directory)?
+
+ /* According to the POSIX standard, we have to assume that a leading ')'
is a
+ * filename argument. Hence it does not matter if the ')' is followed b
y any
+ * other characters.
+ */
+ case ')':
+ return false;
+
+ /* (, ) and ! are part of an expression,
+ * but (2, )3 and !foo are filenames.
+ */
+ case '!':
+ case '(':
+ case ',':
Wrong - you need to treat ',' like you did ')'; a leading comma is always treated as a filename before the first expression is found.
+ if (arg[1])
+ return false;
+ else
+ return true;
+
+ default:
+ return false;
Why not combine the code for case ')': (and as I pointed out, case ',':), with default:?
+ }
+}
Thanks for working on this.
|