testprograms: parse arguments using SDLTest_CommonState
This commit is contained in:
committed by
Anonymous Maarten
parent
8bea41f737
commit
4a6528e3f0
@@ -445,11 +445,6 @@ static Uint32 utf8_decode(char *p, size_t len)
|
||||
return codepoint;
|
||||
}
|
||||
|
||||
static void usage(void)
|
||||
{
|
||||
SDL_Log("usage: testime [--font fontfile]\n");
|
||||
}
|
||||
|
||||
static void InitInput(void)
|
||||
{
|
||||
/* Prepare a rect for text input */
|
||||
@@ -647,42 +642,43 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
int i, done;
|
||||
SDL_Event event;
|
||||
const char *fontname = DEFAULT_FONT;
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
char *fontname = NULL;
|
||||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (state == NULL) {
|
||||
return 1;
|
||||
}
|
||||
for (i = 1; i < argc; i++) {
|
||||
SDLTest_CommonArg(state, i);
|
||||
}
|
||||
for (argc--, argv++; argc > 0; argc--, argv++) {
|
||||
if (SDL_strcmp(argv[0], "--help") == 0) {
|
||||
usage();
|
||||
return 0;
|
||||
}
|
||||
|
||||
else if (SDL_strcmp(argv[0], "--font") == 0) {
|
||||
argc--;
|
||||
argv++;
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
if (argc > 0) {
|
||||
fontname = argv[0];
|
||||
} else {
|
||||
usage();
|
||||
return 0;
|
||||
/* Parse commandline */
|
||||
for (i = 1; i < argc;) {
|
||||
int consumed;
|
||||
|
||||
consumed = SDLTest_CommonArg(state, i);
|
||||
if (SDL_strcmp(argv[i], "--font") == 0) {
|
||||
if (*argv[i+1]) {
|
||||
fontname = argv[i+1];
|
||||
consumed = 2;
|
||||
}
|
||||
}
|
||||
if (consumed <= 0) {
|
||||
static const char *options[] = { "[--font fontfile]", NULL };
|
||||
SDLTest_CommonLogUsage(state, argv[0], options);
|
||||
return 1;
|
||||
}
|
||||
|
||||
i += consumed;
|
||||
}
|
||||
|
||||
if (!SDLTest_CommonInit(state)) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
fontname = GetResourceFilename(fontname, DEFAULT_FONT);
|
||||
|
||||
#ifdef HAVE_SDL_TTF
|
||||
/* Initialize fonts */
|
||||
TTF_Init();
|
||||
@@ -794,6 +790,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
}
|
||||
SDL_free(fontname);
|
||||
CleanupVideo();
|
||||
SDLTest_CommonQuit(state);
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user