It is currently Wed Oct 18, 2017 8:41 pm

All times are UTC - 7 hours



Forum rules


Related:



Post new topic Reply to topic  [ 18 posts ]  Go to page Previous  1, 2
Author Message
PostPosted: Thu Jun 02, 2016 6:29 am 
Offline
User avatar

Joined: Sun Sep 19, 2004 9:28 pm
Posts: 3192
Location: Mountain View, CA, USA
If you need code examples for getopt_long(3), FreeBSD's man page has a decent EXAMPLE section.


Top
 Profile  
 
PostPosted: Thu Jun 02, 2016 6:56 pm 
Offline

Joined: Thu Aug 12, 2010 3:43 am
Posts: 1589
byuu wrote:
There's really nothing wrong with either approach. The big problem is that one side (usually from the former camp, but not always) loves to denigrate the other side. Humans just seem to have a huge issue with accepting that people who disagree with them aren't malicious, crazy, and/or incompetent.

And honestly, the real problem is thinking one should only use one approach and never the other. Happens a lot, sadly.

To be fair this really depends on how much effort is needed. I don't have much problem implementing drawing functions myself, those tend to be simple enough in practice. An INI file parser is not too complex either, for instance. Loading PNG files though? Between handling chunks, decompression, deinterlacing, and all the different bitmap formats, yeah no I'll just leave that to libpng. I have better things to do than spending time on making extremely complex algorithms and then wasting days debugging that hell.

In this case I'd be on the getopt side but only because I know that coping with all the tiny details is hell. And I don't care if the function's code is hellish as long as it's just a library (static or not) and all the awful parts are isolated away from my code.

nicklausw wrote:
calima wrote:
Eh, "breaking all user projects" is more than a minor issue to me.

It's one that getopt wouldn't actually help out with, because the args order changed.

Looks like you can distinguish between both cases simply by figuring out whether -o is present or not (if it's not present, try to use the last argument as the output instead - that'd make it compatible with old projects).

EDIT: you can also use the file extension if you want to be safer against misuse (i.e. trigger the compatibility behavior only if the would-be output also ends in .o)


Top
 Profile  
 
PostPosted: Wed Jun 08, 2016 4:29 pm 
Offline

Joined: Mon Jul 02, 2012 7:46 am
Posts: 759
getopt allows you to handle any "extra" options at the end of the command line separately from the "flagged" options (e.g. -x -y somthing_y -z something_z other options go here).

Code:
while((opt = getopt(argc, argv, "abc:dDeEfg")) != -1)
{
    switch(opt)
    {
    . . .
    }
}

while (optind < argc)
{
    // do something with argv[optind++]
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ]  Go to page Previous  1, 2

All times are UTC - 7 hours


Who is online

Users browsing this forum: adam_smasher and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group