[Add] Long options for command line -- VLack's recommendation.

This commit is contained in:
Allanis 2013-02-03 17:45:38 +00:00
parent 46caaa21ad
commit 7910dac9c3

View File

@ -4,6 +4,7 @@
#include <lualib.h> #include <lualib.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include <getopt.h>
#include "def.h" #include "def.h"
#include "log.h" #include "log.h"
@ -37,14 +38,14 @@ static void update_all(void);
// Usage. // Usage.
static void print_usage(char** argv) { 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("Options are:");
LOG("\t-f - Fullscreen"); LOG("\t-f, --fullscreen - Fullscreen");
LOG("\t-w n - Set width to (n)"); //LOG("\t-w n - Set width to (n)");
LOG("\t-h n - Set height to (n)"); //LOG("\t-h n - Set height to (n)");
LOG("\t-j n - Use joystick (n)"); LOG("\t-j n, --joystick n - Use joystick (n)");
LOG("\t-J s - Use joystick whose name contains (s)"); LOG("\t-J s, --joystick s - Use joystick whose name contains (s)");
LOG("\t-h - Display this message and exit."); LOG("\t--help - Display this message and exit.");
LOG("\t-v - Print the version and exit"); LOG("\t-v - Print the version and exit");
} }
@ -134,8 +135,17 @@ int main(int argc, char** argv) {
lua_close(L); lua_close(L);
// Parse arguments. // 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; 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) { switch(c) {
case 'f': case 'f':
gl_screen.fullscreen = 1; gl_screen.fullscreen = 1;