Permalink
Browse files

First cut at getopt based launcher

  • Loading branch information...
1 parent e571465 commit f1ba5423d8e6a46d4372469ab8a1317e42fbc6bd @abedra committed Jan 9, 2012
Showing with 48 additions and 14 deletions.
  1. +48 −14 bungelo.c
View
@@ -1,35 +1,69 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <getopt.h>
#include "bungeloClient.h"
#include "bungeloServer.h"
static void printUsage(void) {
- printf("Usage: bungelo [--client | --server]\n");
+ printf("Usage: bungleo\n -h, --help\n -c, --client\n -s, --server\n");
}
int main(int argc, char **argv)
{
- char *mode;
+ int client = 0;
+ int server = 0;
+ int option_index = 0;
+ int c;
+
+ while(1) {
+ static struct option long_options[] =
+ {
+ {"help", no_argument, 0, 'h'},
+ {"client", no_argument, 0, 'c'},
+ {"server", no_argument, 0, 's'},
+ {0, 0, 0, 0}
+ };
- if(argc != 2) {
- printUsage();
- return 1;
- }
+ c = getopt_long(argc, argv, "hcs", long_options, &option_index);
- mode = argv[1];
+ if(c == -1) break;
- if(strcmp(mode, "--client") == 0) {
- printf("Starting bungelo client...\n");
+ switch(c)
+ {
+ case 'h':
+ printUsage();
+ return 0;
+ break;
+ case 'c':
+ client = 1;
+ break;
+ case 's':
+ server = 1;
+ break;
+ case '?':
+ break;
+ default:
+ abort();
+ }
+ }
+
+ if (client && server) {
+ printUsage();
+ return 1;
+ } else if (!client && !server) {
+ printUsage();
+ return 1;
+ } else if (server) {
+ printf("Starting bungle-o server...\n");
startBungeloClient();
- } else if(strcmp(mode, "--server") == 0) {
- printf("Starting bungelo server...\n");
+ } else if (client) {
+ printf("Starting bungle-o client...\n");
startBungeloServer();
} else {
- printf("Unknown option %s\n", mode);
printUsage();
- return 2;
+ return 1;
}
-
+
return 0;
}

0 comments on commit f1ba542

Please sign in to comment.