Page 2 of 2

Re: Note to all WLA-DX users: change in argv parser

Posted: Thu Jun 02, 2016 6:29 am
by koitsu
If you need code examples for getopt_long(3), FreeBSD's man page has a decent EXAMPLE section.

Re: Note to all WLA-DX users: change in argv parser

Posted: Thu Jun 02, 2016 6:56 pm
by Sik
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)

Re: Note to all WLA-DX users: change in argv parser

Posted: Wed Jun 08, 2016 4:29 pm
by qwertymodo
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: Select all

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

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