Project

General

Profile

Actions

Bug #1237

closed

patch to add getopt parsing to expr

Added by josepht about 15 years ago. Updated almost 15 years ago.

Status:
Closed
Priority:
Low
Assignee:
-
Category:
-
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:

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


Files

expr.patch (810 Bytes) expr.patch josepht, 01/20/2009 04:32 AM
expr.y.diff (844 Bytes) expr.y.diff joerg, 01/20/2009 01:07 PM
expr.patch (590 Bytes) expr.patch josepht, 01/20/2009 04:25 PM
Actions #1

Updated by josepht about 15 years ago

Forgot the patch.

Joe

Actions #2

Updated by joerg about 15 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

Actions #3

Updated by joerg about 15 years ago

Patch.

Actions #4

Updated by josepht about 15 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

Actions #5

Updated by joerg about 15 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

Actions #6

Updated by josepht about 15 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

Actions #7

Updated by joerg about 15 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

Actions #8

Updated by josepht about 15 years ago

Okay. Here's the new patch.

Joe

Actions #9

Updated by swildner almost 15 years ago

was committed -> ee2af4a46fc2ddef3a589ee9d5b58aa1c1f923bc

Actions

Also available in: Atom PDF