Skip to content

Commit

Permalink
Merge pull request #36 from 375gnu/if-to-switch
Browse files Browse the repository at this point in the history
Replace `if` with `switch` in getopt() parsing.
  • Loading branch information
Celestia committed Apr 20, 2018
2 parents a2aef0a + 254ea3c commit c1c4770
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
22 changes: 10 additions & 12 deletions src/buildstardb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1090,36 +1090,34 @@ int main(int argc, char* argv[])
int c;
while((c=getopt(argc,argv,"v::qd:"))>-1)
{
if (c=='?')
switch (c)
{
case '?':
cout << "Usage: buildstardb [-v[<verbosity_level>] [-q] [-d <drop-level>\n";
exit(1);
}
else if (c=='v')
{
case 'v':
if (optarg)
{
{
verbose=(int)atol(optarg);
if (verbose<-1)
verbose=-1;
else if (verbose>3)
verbose=3;
}
}
else
verbose=1;
}
else if (c=='d')
{ /* Dropstar level. 0 = don't drop stars
break;
case 'd':
/* Dropstar level. 0 = don't drop stars
1 = drop only non-naked eye visible stars
2 = drop all stars with strange values */
dropstars=(int)atol(optarg);
if (dropstars<0)
dropstars=0;
else if (dropstars>2)
dropstars=2;
}
else if (c=='q')
{
break;
case 'q':
verbose=-1;
}
}
Expand Down
15 changes: 7 additions & 8 deletions src/celestia/glutmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,24 +462,23 @@ int main(int argc, char* argv[])
ready = false;

char c;
int startfile = 0;
int startfile = 0;
while ((c = getopt(argc, argv, "v::f")) > -1)
{
if (c == '?')
switch (c)
{
case '?':
cout << "Usage: celestia [-v] [-f <filename>]\n";
exit(1);
}
else if (c == 'v')
{
case 'v':
if(optarg)
SetDebugVerbosity(atoi(optarg));
else
SetDebugVerbosity(0);
break;
case 'f':
startfile = 1;
}
else if (c == 'f') {
startfile = 1;
}
}

appCore = new CelestiaCore();
Expand Down

0 comments on commit c1c4770

Please sign in to comment.