From 7910dac9c3c2d4661ce6a14f6a262cbfbfc558c3 Mon Sep 17 00:00:00 2001
From: Allanis <allanis@saracraft.net>
Date: Sun, 3 Feb 2013 17:45:38 +0000
Subject: [PATCH] [Add] Long options for command line -- VLack's
 recommendation.

---
 src/main.c | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/src/main.c b/src/main.c
index fb37a60..562ba14 100644
--- a/src/main.c
+++ b/src/main.c
@@ -4,6 +4,7 @@
 #include <lualib.h>
 #include <unistd.h>
 #include <string.h>
+#include <getopt.h>
 
 #include "def.h"
 #include "log.h"
@@ -37,15 +38,15 @@ static void update_all(void);
 
 // Usage.
 static void print_usage(char** argv) {
-  LOG("USAGE: %s [-f] [-j n | -J s] [-hv]", argv[0]);
+  LOG("USAGE: %s [OPTION]", argv[0]);
   LOG("Options are:");
-  LOG("\t-f   - Fullscreen");
-  LOG("\t-w n - Set width to (n)");
-  LOG("\t-h n - Set height to (n)");
-  LOG("\t-j n - Use joystick (n)");
-  LOG("\t-J s - Use joystick whose name contains (s)");
-  LOG("\t-h   - Display this message and exit.");
-  LOG("\t-v   - Print the version and exit");
+  LOG("\t-f,    --fullscreen  - Fullscreen");
+  //LOG("\t-w n - Set width to (n)");
+  //LOG("\t-h n - Set height to (n)");
+  LOG("\t-j n,  --joystick n  - Use joystick (n)");
+  LOG("\t-J s,  --joystick s  - Use joystick whose name contains (s)");
+  LOG("\t--help               - Display this message and exit.");
+  LOG("\t-v                   - Print the version and exit");
 }
 
 int main(int argc, char** argv) {
@@ -134,8 +135,17 @@ int main(int argc, char** argv) {
   lua_close(L);
 
   // Parse arguments.
+  static struct option long_options[] = {
+    { "fullscreen", no_argument, 0, 'f' },
+    { "joystick", required_argument, 0, 'j' },
+    { "joystick", required_argument, 0, 'J' },
+    { "help", no_argument, 0, 'h' },
+    { "version", no_argument, 0, 'v' },
+    { 0, 0, 0, 0 }
+  };
+  int option_index = 0;
   int c = 0;
-  while((c = getopt(argc, argv, "fJ:j:hv")) != -1) {
+  while((c = getopt_long(argc, argv, "fJ:j:hv", long_options, &option_index)) != -1) {
     switch(c) {
       case 'f':
         gl_screen.fullscreen = 1;