Created
August 21, 2009 16:39
-
-
Save tonetheman/172171 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <signal.h> | |
#include <getopt.h> | |
using namespace std; | |
char * __PORT = 0; | |
int PORT = -1; | |
void dbg(const char * str) { | |
cout << "dbg: " << str << endl; | |
} | |
void finish(int __ignore) { | |
dbg("quitting program"); | |
} | |
int main(int argc, char* argv[]) { | |
signal(SIGINT, finish); | |
struct option const long_opts[] = { | |
{"port", required_argument, NULL, 'p'}, | |
{0,0,0,0} | |
}; | |
int c; | |
// :p means this command line arg has a parameter passed behind it | |
while ((c = getopt_long(argc,argv, "p:", long_opts, 0))!=-1) { | |
switch(c) { | |
case 0: | |
break; | |
case 'p': | |
__PORT = optarg; | |
break; | |
default: | |
cout << "got a default case: " << c << endl; | |
break; | |
} | |
} | |
if (__PORT) { | |
PORT = atoi(__PORT); | |
cout << "info: port is: " << PORT << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment