Skip to content

Instantly share code, notes, and snippets.

@tonetheman
Created August 21, 2009 16:39
Show Gist options
  • Save tonetheman/172171 to your computer and use it in GitHub Desktop.
Save tonetheman/172171 to your computer and use it in GitHub Desktop.
#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