Re: getopt compatibility

"ZIGLIO, Frediano, VF-IT" <[email protected]>
Newsgroups gmane.comp.db.tds.freetds
Message-ID <[email protected]>
> > > > In tsql
> > > > getopt is restarted to read options. It's currently 
> > > > restarted using GNU getopt way, that is setting optind with 0. 
> > > 
> > > Looking at the code, I think the most portable choice -- and 
> > > probably the
> > > least work -- is to refactor tsql.c: call getopt(3) in only 
> > > one place, and
> > > don't reset optind/optreset.  
> > 
> > ehm.... that is only for main argc/argv ??
> 
> So ... are you suggesting I should read the code before 
> offering advice? 
> Don't you understand how much harder that is?  
> 

No, just I don't understand if you supported one of my options or just
add a new one to think about :)

About code getopt is called in three cases:
- main argc/argv parameters
- -o options argument, for instance "-o fq" cause a "go -fq" to be built
and parsed
- go command with options
The portability problem is to be able to parse two set of parameters. My
problem raise from a command line like 

tsql -S sss -U uuu -P ppp -o fhq 

getopt is used to parse { "tsql", "-S", "sss", "-U", "uuu", "-P", "ppp",
"-o", "fhq" } array, then getopt is used again to parse { "go", "-fhq" }
array.


> OK, I see: the "go flags".  
> 
> www.opengroup.org/onlinepubs/ 000095399/functions/getopt.html
> 
> There is no standard for resetting getopt.  
> 
> Do what you think is easiest or most interesting.  I don't 
> see the need --
> unless you want to -- to develop an autoconf test for this.  (A quick
> search didn't turn up anything, and "getopt" doesn't appear in the
> autoconf info file.  It seems it's a void that needs filling.)  
> 

personally I don't like that much autoconf tests and this is quite
difficult to test. I found a test about optreset but nothing about HP-UX
:(
This is why I suggested to write a small parse for our options cause
handling no argument is quite easy to implement (just skip no options
argument and return all letters we need). 

> The quickest and least kludgy answer is probably to write a function:
> 
> 	static int reset_getopt();
> 
> that does what you want, complete with all the #ifs you need.  :-/  
> 
> At least it won't be very big!  
> 

yes, this is also a good idea. Testing for HP-UX from code is not that
difficult and optreset variable can be tested quite easily in autoconf,
something like

static int 
reset_getopt(void)
{
#if hpux
  optind = 1;
#else
#if HAVE_OPTRESET
  optreset = 1; 
#endif
  optind = 0;
#endif
}

> >>> try to detect HP-UX and reset optind with 1?
> 
> ISTR we already test HP/UX symbols somewhere?  
> 

I remember a linker problem with... mumble... gethostaddr  ?? Something
network related.

> > > I think refactoring is best because otherwise you need an 
> > > autoconf test ...
> > > with a bunch of #define macros.  It would look like 
> > > src/tds/net.c.  :-(
> > 
> > I know.. net.c is ugly but it does a lot of system 
> optimizations and all
> > contained in a single file... all others use mainly plain C and some
> > allocation/deallocation function...
> 
> Yeah, a dancing bear: not graceful, but impressive that it 
> does what it
> does.  
> 

:)

yes, I think I'll try to review get_opt_flags

freddy77
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.