Skip to content

Commit

Permalink
getopt-based arg parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski committed Sep 9, 2012
1 parent 7812297 commit 9957933
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions posterize.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,24 @@ static void voronoi(const double histogram[], unsigned int palette[])
}
}

#include <unistd.h>

int main(int argc, char *argv[])
{
int argn=1;
bool dither = false;
if (argc==3 && 0==strcmp("-d", argv[1])) {
dither=true;
argn++;
int ch;
while ((ch = getopt(argc, argv, "hvdq:")) != -1) {
switch (ch) {
case 'd': dither = true; break;
case '?': case 'h':
default:
usage(argv[0]);
return 1;
}
}
int maxcolors=0;
int argn = optind;

if (argc==(argn+1)) {
maxcolors=atoi(argv[argn]);
argn++;
Expand Down

0 comments on commit 9957933

Please sign in to comment.