linux-Gg's getopt_long commandline parser (last commit missed one file)
git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@110 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
+68
-47
@@ -18,8 +18,10 @@
|
|||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <getopt.h>
|
||||||
#else
|
#else
|
||||||
#include <direct.h>
|
#include <direct.h>
|
||||||
|
#include "getopt/getopt.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "libs/graphics/gfx_common.h"
|
#include "libs/graphics/gfx_common.h"
|
||||||
@@ -27,7 +29,6 @@
|
|||||||
#include "libs/input/input_common.h"
|
#include "libs/input/input_common.h"
|
||||||
#include "libs/tasklib.h"
|
#include "libs/tasklib.h"
|
||||||
|
|
||||||
|
|
||||||
BOOLEAN FileExists (char *filename)
|
BOOLEAN FileExists (char *filename)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
@@ -56,65 +57,85 @@ CDToContentDir (char *contentdir)
|
|||||||
int
|
int
|
||||||
main (int argc, char *argv[])
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
int gfxdriver = TFB_GFXDRIVER_SDL_PURE;
|
int gfxdriver = TFB_GFXDRIVER_SDL_PURE;
|
||||||
int gfxflags = 0;
|
int gfxflags = 0;
|
||||||
int width = 640, height = 480, bpp = 16;
|
int width = 640, height = 480, bpp = 16;
|
||||||
int frequency = 44100;
|
int frequency = 44100;
|
||||||
char contentdir[1000];
|
char contentdir[1000];
|
||||||
|
|
||||||
|
int option_index = 0, c;
|
||||||
|
static struct option long_options[] =
|
||||||
|
{
|
||||||
|
{"res", 1, NULL, 'r'},
|
||||||
|
{"bpp", 1, NULL, 'd'},
|
||||||
|
{"fullscreen", 0, NULL, 'f'},
|
||||||
|
{"opengl", 0, NULL, 'o'},
|
||||||
|
{"bilinear", 0, NULL, 'b'},
|
||||||
|
{"frequency", 1, NULL, 'q'},
|
||||||
|
{"fps", 0, NULL, 'p'},
|
||||||
|
{"tv", 0, NULL, 't'},
|
||||||
|
{"contentdir", 1, NULL, 'c'},
|
||||||
|
{"help", 0, NULL, 'h'},
|
||||||
|
{0, 0, 0, 0}
|
||||||
|
};
|
||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
strcpy (contentdir, "content");
|
strcpy (contentdir, "content");
|
||||||
#else
|
#else
|
||||||
strcpy (contentdir, "../../content");
|
strcpy (contentdir, "../../content");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// TODO: proper commandline parser, this is just a quick hack
|
while ((c = getopt_long(argc, argv, "r:d:fobq:ptc:?h", long_options, &option_index)) != -1)
|
||||||
for (i=1;i<argc;++i)
|
|
||||||
{
|
{
|
||||||
if (!strcmp(argv[i],"-res"))
|
switch (c) {
|
||||||
{
|
case 'r':
|
||||||
i++;
|
sscanf(optarg, "%dx%d", &width, &height);
|
||||||
sscanf(argv[i],"%dx%d",&width,&height);
|
break;
|
||||||
|
case 'd':
|
||||||
|
sscanf(optarg, "%d", &bpp);
|
||||||
|
break;
|
||||||
|
case 'f':
|
||||||
|
gfxflags |= TFB_GFXFLAGS_FULLSCREEN;
|
||||||
|
break;
|
||||||
|
case 'o':
|
||||||
|
gfxdriver = TFB_GFXDRIVER_SDL_OPENGL;
|
||||||
|
break;
|
||||||
|
case 'b':
|
||||||
|
gfxflags |= TFB_GFXFLAGS_BILINEAR_FILTERING;
|
||||||
|
break;
|
||||||
|
case 'q':
|
||||||
|
sscanf(optarg, "%d", &frequency);
|
||||||
|
break;
|
||||||
|
case 'p':
|
||||||
|
gfxflags |= TFB_GFXFLAGS_SHOWFPS;
|
||||||
|
break;
|
||||||
|
case 't':
|
||||||
|
gfxflags |= TFB_GFXFLAGS_TVEFFECT;
|
||||||
|
break;
|
||||||
|
case 'c':
|
||||||
|
sscanf(optarg, "%s", contentdir);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
printf ("\nOption %s not found!\n", long_options[option_index].name);
|
||||||
|
case '?':
|
||||||
|
case 'h':
|
||||||
|
printf("\nThe Ur-Quan Masters\n");
|
||||||
|
printf("Options:\n");
|
||||||
|
printf(" -r, --res=WIDTHxHEIGHT\n");
|
||||||
|
printf(" -d, --bpp=BITSPERPLANE\n");
|
||||||
|
printf(" -f, --fullscreen\n");
|
||||||
|
printf(" -o, --opengl\n");
|
||||||
|
printf(" -b, --bilinear\n");
|
||||||
|
printf(" -q, --frequency=FREQUENCY\n");
|
||||||
|
printf(" -p, --fps\n");
|
||||||
|
printf(" -t, --tv\n");
|
||||||
|
printf(" -c, --contentdir=CONTENTDIR\n");
|
||||||
|
return 0;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else if (!strcmp(argv[i],"-bpp"))
|
|
||||||
{
|
|
||||||
i++;
|
|
||||||
sscanf(argv[i],"%d",&bpp);
|
|
||||||
}
|
|
||||||
else if (!strcmp(argv[i],"-fullscreen"))
|
|
||||||
{
|
|
||||||
gfxflags |= TFB_GFXFLAGS_FULLSCREEN;
|
|
||||||
}
|
|
||||||
else if (!strcmp(argv[i],"-opengl"))
|
|
||||||
{
|
|
||||||
gfxdriver = TFB_GFXDRIVER_SDL_OPENGL;
|
|
||||||
}
|
|
||||||
else if (!strcmp(argv[i],"-bilinear"))
|
|
||||||
{
|
|
||||||
gfxflags |= TFB_GFXFLAGS_BILINEAR_FILTERING;
|
|
||||||
}
|
|
||||||
else if (!strcmp(argv[i],"-frequency"))
|
|
||||||
{
|
|
||||||
i++;
|
|
||||||
sscanf(argv[i],"%d",&frequency);
|
|
||||||
}
|
|
||||||
else if (!strcmp(argv[i],"-fps"))
|
|
||||||
{
|
|
||||||
gfxflags |= TFB_GFXFLAGS_SHOWFPS;
|
|
||||||
}
|
|
||||||
else if (!strcmp(argv[i],"-tv"))
|
|
||||||
{
|
|
||||||
gfxflags |= TFB_GFXFLAGS_TVEFFECT;
|
|
||||||
}
|
|
||||||
else if (!strcmp(argv[i],"-content"))
|
|
||||||
{
|
|
||||||
i++;
|
|
||||||
sscanf(argv[i], "%s", contentdir);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CDToContentDir (contentdir);
|
CDToContentDir (contentdir);
|
||||||
|
|
||||||
InitThreadSystem ();
|
InitThreadSystem ();
|
||||||
InitTimeSystem ();
|
InitTimeSystem ();
|
||||||
|
|||||||
Reference in New Issue
Block a user