DragonFly bugs List (threaded) for 2009-01
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
[
Date Index][
Thread Index]
Re: patch to add getopt parsing to expr
On Tue, Jan 20, 2009 at 05:11:34PM +0100, Joerg Sonnenberger wrote:
> On Tue, Jan 20, 2009 at 11:01:33AM -0500, Joe Talbott wrote:
> > On Tue, Jan 20, 2009 at 04:52:45PM +0100, Joerg Sonnenberger wrote:
> > > On Tue, Jan 20, 2009 at 10:18:37AM -0500, Joe Talbott wrote:
> > > > Since POSIX requires arguments beginning with '-' to be options
> > > > shouldn't the following result in an error?
> > >
> > > No. POSIX only says that -- has to be supported to disable the use of
> > > options. It doesn't say that options have to be used.
> >
> > What about this?
> >
> > Guideline 14:
> > If an argument can be identified according to Guidelines 3 through
> > 10 as an option, or as a group of options without option-arguments
> > behind one '-' delimiter, then it should be treated as such.
>
> Doesn't apply. SUS leaves it open whether or not expr supports options.
> It does require expr to support --. Consider "expr -1".
>
Okay. Here's the new patch.
Joe
diff --git a/bin/expr/expr.y b/bin/expr/expr.y
index 0bcd6e0..4807d9d 100644
--- a/bin/expr/expr.y
+++ b/bin/expr/expr.y
@@ -244,12 +244,25 @@ is_zero_or_null(struct val *vp)
/* NOTREACHED */
}
+static void
+usage(void)
+{
+ fprintf(stderr,
+ "usage: expr expression\n");
+ exit(EXIT_FAILURE);
+}
+
int
-main (int argc __unused, char **argv)
+main (int argc, char **argv)
{
setlocale (LC_ALL, "");
- av = argv + 1;
+ if (argc > 1 && strcmp(argv[1], "--"))
+ av = argv + 1;
+ else if (argc > 2)
+ av = argv + 2;
+ else
+ usage();
yyparse ();
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
[
Date Index][
Thread Index]