Bug 17612 - ability to parse argv[0]
Summary: ability to parse argv[0]
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: popt
Version: 7.1
Hardware: All
OS: Linux
Target Milestone: ---
Assignee: Jeff Johnson
QA Contact:
Keywords: FutureFeature
Depends On:
TreeView+ depends on / blocked
Reported: 2000-09-18 17:06 UTC by Matt Domsch
Modified: 2008-05-01 15:37 UTC (History)
1 user (show)

Clone Of:
Last Closed: 2000-10-09 17:38:41 UTC

Attachments (Terms of Use)

Description Matt Domsch 2000-09-18 17:06:09 UTC
popt cannot parse argv[0].  This is proper behavior if you're only using 
popt to parse command line arguments (even this is debateable, as one can 
have one binary application that is either hardlinked or simlinked to 
different names, and the application switches on argv[0] to act 
differently.  Think collage.), but if you want to use popt to parse 
configuration files, it would be good to be able to parse argv[0].

Comment 1 Jeff Johnson 2000-10-06 21:01:49 UTC
rpm uses popt to parse options, and does logic based on argv[0] tests. The 
"trick" is to
call poptGetContext with different values for the 1st and 4th args, and to make
use of nested "struct poptOption" tables using POPT_ARG_INCLUDE_TABLES to
eliminate redundancy.

Otherwise, I need an explicit example of what you are trying to do to even
an implementation. Feel free to reopen with a more explicit example ...

Comment 2 Matt Domsch 2000-10-09 14:56:04 UTC
MKJ wrote a nice program 'ttywatch'.  It uses popt to parse a configuration 
file (see below).  Essentially, each line is read in and placed in argv, and 
then parsed using popt.  As argv[0] can't be parsed, the first argument (--
name) actually has to be shifted by one, and a dummy value put in argv[0].
See MKJ for further details, and look at ttywatch in your CVS to see what he 

### A sample configuration follows:
# --name m1
# --name m2 --port /dev/ttyS1 --bps 9600
# --name m3 --port /dev/ttyS2 --bps 57600
### machine one (m1) is connected to ttyS0 and talks 115200 bps (default)
###   its log is kept in /var/log/ttywatch/m1
###   /dev/m1 is a link to /dev/ttyS0
### machine two (m2) is connected to ttyS1 and talks 9600 bps
###   its log is kept in /var/log/ttywatch/m2
### machine three (m3) is connected to ttyS2 and talks 57600 bps
###   its log is kept in /var/log/ttywatch/m3
--name ttyS0

Comment 3 Jeff Johnson 2000-10-09 17:38:38 UTC
Per MKJ, the functionality is apparently already in popt, but not documented. He
to send me a doco patch. Please reopen if on or the other of us Johnson's fails
to fix :-)

Note You need to log in before you can comment on or make changes to this bug.