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:
gewlitys
2002-10-11 19:39:59 +00:00
parent ac04c0fb3d
commit 1c7473ee02
+59 -38
View File
@@ -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,61 +57,81 @@ 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"))
{
i++;
sscanf(argv[i],"%dx%d",&width,&height);
}
else if (!strcmp(argv[i],"-bpp"))
{
i++;
sscanf(argv[i],"%d",&bpp);
}
else if (!strcmp(argv[i],"-fullscreen"))
{ {
switch (c) {
case 'r':
sscanf(optarg, "%dx%d", &width, &height);
break;
case 'd':
sscanf(optarg, "%d", &bpp);
break;
case 'f':
gfxflags |= TFB_GFXFLAGS_FULLSCREEN; gfxflags |= TFB_GFXFLAGS_FULLSCREEN;
} break;
else if (!strcmp(argv[i],"-opengl")) case 'o':
{
gfxdriver = TFB_GFXDRIVER_SDL_OPENGL; gfxdriver = TFB_GFXDRIVER_SDL_OPENGL;
} break;
else if (!strcmp(argv[i],"-bilinear")) case 'b':
{
gfxflags |= TFB_GFXFLAGS_BILINEAR_FILTERING; gfxflags |= TFB_GFXFLAGS_BILINEAR_FILTERING;
} break;
else if (!strcmp(argv[i],"-frequency")) case 'q':
{ sscanf(optarg, "%d", &frequency);
i++; break;
sscanf(argv[i],"%d",&frequency); case 'p':
}
else if (!strcmp(argv[i],"-fps"))
{
gfxflags |= TFB_GFXFLAGS_SHOWFPS; gfxflags |= TFB_GFXFLAGS_SHOWFPS;
} break;
else if (!strcmp(argv[i],"-tv")) case 't':
{
gfxflags |= TFB_GFXFLAGS_TVEFFECT; gfxflags |= TFB_GFXFLAGS_TVEFFECT;
} break;
else if (!strcmp(argv[i],"-content")) case 'c':
{ sscanf(optarg, "%s", contentdir);
i++; break;
sscanf(argv[i], "%s", contentdir); 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;
} }
} }