Bug #1237

patch to add getopt parsing to expr

Added by josepht over 5 years ago. Updated almost 5 years ago.

Status:ClosedStart date:
Priority:LowDue date:
Assignee:-% Done:

0%

Category:-
Target version:-

Description

Here's a patch to add getopt(3) support to expr so that -- is accepted as
required by POSIX. This was pointed out by vstemen on IRC. I'll
commit sometime after the release if there are no objections.

Joe

expr.patch Magnifier (810 Bytes) josepht, 01/20/2009 04:32 AM

expr.y.diff Magnifier (844 Bytes) joerg, 01/20/2009 01:07 PM

expr.patch Magnifier (590 Bytes) josepht, 01/20/2009 04:25 PM

History

#1 Updated by josepht over 5 years ago

Forgot the patch.

Joe

#2 Updated by joerg over 5 years ago

The use of getopt here is wrong. Besides, using getopt is taking a
sledgehammer to crack a nut. Attached is the corresponding fix for
NetBSD, the explicit check for having at least one argument is better
anyway.

Joerg

#3 Updated by joerg over 5 years ago

Patch.

#4 Updated by josepht over 5 years ago

Since POSIX requires arguments beginning with '-' to be options
shouldn't the following result in an error?

expr -d=zzz : '.*=\(.*\)'

Where:

expr -- -d=zzz : '.*=\(.*\)'

should be the correct usage. I opted to use getopt() since FreeBSD's
expr accepts -e. The "-" was inadvertently left in the patch.

Thanks,
Joe

#5 Updated by joerg over 5 years ago

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.

Joerg

#6 Updated by josepht over 5 years ago

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.

Joe

#7 Updated by joerg over 5 years ago

Doesn't apply. SUS leaves it open whether or not expr supports options.
It does require expr to support --. Consider "expr -1".

Joerg

#8 Updated by josepht over 5 years ago

Okay. Here's the new patch.

Joe

#9 Updated by swildner almost 5 years ago

was committed -> ee2af4a46fc2ddef3a589ee9d5b58aa1c1f923bc

Also available in: Atom PDF