[Add] Long options for command line -- VLack's recommendation.
This commit is contained in:
parent
46caaa21ad
commit
7910dac9c3
28
src/main.c
28
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;
|
||||
|
Loading…
Reference in New Issue
Block a user