473,320 Members | 2,117 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Calling getopt with new arguments

I'd like to call getopt with one set of arguments, and once that's
completely done call it again with an entirely different set of
arguments. I've found though that at least with the getopt
implementation common to both glibc and newlib, getopt has to be
"cleaned up" in between. The glibc source code shows that to clean it
up either optind must be set to zero or __getopt_initialized must be
set to non-zero. The latter is clearly non-standard, is the former
possibly more standard? It seems to me this issue must have been
encountered and addressed sometime before.

I ran into a bug with busybox because it set optind to 1 to clean up
getopt, but this was insufficient with newlib (and glibc) and was
causing errors when parsing options.

Thanks,
Shaun

Nov 15 '05 #1
1 1538
On 22 Jul 2005 23:49:14 -0700, Shaun Jackman
<sj******@gmail.com> wrote:
I'd like to call getopt with one set of arguments, and once that's
completely done call it again with an entirely different set of
arguments. I've found though that at least with the getopt
implementation common to both glibc and newlib, getopt has to be
"cleaned up" in between. The glibc source code shows that to clean it
up either optind must be set to zero or __getopt_initialized must be
set to non-zero. The latter is clearly non-standard, is the former
possibly more standard? It seems to me this issue must have been
encountered and addressed sometime before.
It is not standard in C at all, the C specification says nothing about
getopt(). It is defined in IEEE Std 1003.1-2001, but that says nothing
about re-initialising it.

http://www.opengroup.org/onlinepubs/...ns/getopt.html
I ran into a bug with busybox because it set optind to 1 to clean up
getopt, but this was insufficient with newlib (and glibc) and was
causing errors when parsing options.


Since it is not defined that there is any standard way of doing it, you
will have to read other documentation (or the code), or code your own
version (as I have; I don't know that mine alows restarting either, I
don't remember designing it in). The latter (having your own version)
is probably best, then you won't be dependent on the OS libraries
supporting it.

Chris C
Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: David Bear | last post by:
I'm stumped. Trying to follow the docs and .. failure. here's the args >>> args '-Middwb@mainex1.asu.edu -AKHAAM@prlinux+898 -CA --D2003-08-20-09:28:13.417 -Ff -Hprlinux...
4
by: Dan Rawson | last post by:
Is there any way to force getopt to process one option first?? I'd like to be able to pass in the name of a configuration file for my application, then have the remaining command-line parameters...
3
by: Don Low | last post by:
Hi, I'm going over a script that demonstrates the getopt function. I include the script here: #! /usr/bin/python import sys, getopt, string
1
by: M.N.A.Smadi | last post by:
hi; I have a perl script that I need to port to python. The script takes input from the command line. Is there a standard way of processing command line arguments based on the -flag preceeding...
14
by: José de Paula | last post by:
Is getopt() and its companions, commonly found in GNU libc and other Unices libc, part of the C standard? Another doubt: I have a switch inside a while loop; is there a way to break out of the...
4
by: pinkfloydhomer | last post by:
I want to be able to do something like: myscript.py * -o outputfile and then have the shell expand the * as usual, perhaps to hundreds of filenames. But as far as I can see, getopt can only...
7
by: munkyeetr | last post by:
I'm new to PERL, and am trying to use the Getopt::EvaP module to parse my command-line arguments, but I am a little lost as to how to make this work. So far I have downloaded and installed the...
20
by: Casey | last post by:
Is there an easy way to use getopt and still allow negative numbers as args? I can easily write a workaround (pre-process the tail end of the arguments, stripping off any non-options including...
1
by: moreati | last post by:
Recently I discovered the re module doesn't support POSIX character classes: Python 2.5.2 (r252:60911, Apr 21 2008, 11:12:42) on linux2 Type "help", "copyright", "credits" or "license" for...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.