Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix informational command-line arguments not working with -console #1168

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions desktop_version/src/Vlogging.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,12 @@ void vlog_open_console(void)
vlog_error("Could not redirect STDERR to console.");
}

handle = freopen("CON", "r", stdin);
if (handle == NULL)
{
vlog_error("Could not redirect STDIN to console.");
}

check_color_support();

if (!SetConsoleOutputCP(CP_UTF8))
Expand Down
106 changes: 74 additions & 32 deletions desktop_version/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,16 +363,35 @@ static void emscriptenloop(void)
}
#endif

static void keep_console_open(const bool open_console)
{
if (!open_console)
{
return;
}

printf("Press ENTER to quit.");

int c;
do
{
c = getchar();
}
while (c != '\n' && c != EOF);
}

int main(int argc, char *argv[])
{
char* baseDir = NULL;
char* assetsPath = NULL;
char* langDir = NULL;
char* fontsDir = NULL;
bool seed_use_sdl_getticks = false;
#ifdef _WIN32
bool open_console = false;
#endif
bool print_version = false;
bool print_addresses = false;
int invalid_arg = 0;
int invalid_partial_arg = 0;

vlog_init();

Expand All @@ -386,41 +405,16 @@ int main(int argc, char *argv[])
} \
else \
{ \
vlog_error("%s option requires one argument.", argv[i]); \
VVV_exit(1); \
invalid_partial_arg = i; \
}

if (ARG("-version"))
{
/* Just print the version and exit. No vlogging. */
puts(
"VVVVVV " RELEASE_VERSION
#ifdef MAKEANDPLAY
" [M&P]"
#endif
);
#ifdef INTERIM_VERSION_EXISTS
puts(COMMIT_DATE);
puts(INTERIM_COMMIT);
puts(BRANCH_NAME);
#endif
VVV_exit(0);
print_version = true;
}
else if (ARG("-addresses"))
{
printf("cl : %p\n", (void*) &cl);
printf("ed : %p\n", (void*) &ed);
printf("game : %p\n", (void*) &game);
printf("gameScreen : %p\n", (void*) &gameScreen);
printf("graphics : %p\n", (void*) &graphics);
printf("help : %p\n", (void*) &help);
printf("key : %p\n", (void*) &key);
printf("map : %p\n", (void*) &map);
printf("music : %p\n", (void*) &music);
printf("obj : %p\n", (void*) &obj);
printf("script : %p\n", (void*) &script);

VVV_exit(0);
print_addresses = true;
}
else if (ARG("-renderer"))
{
Expand Down Expand Up @@ -541,8 +535,7 @@ int main(int argc, char *argv[])
#undef ARG
else
{
vlog_error("Error: invalid option: %s", argv[i]);
VVV_exit(1);
invalid_arg = i;
}
}

Expand All @@ -557,6 +550,54 @@ int main(int argc, char *argv[])
}
#endif

if (invalid_arg > 0)
{
vlog_error("Error: invalid option: %s", argv[invalid_arg]);
keep_console_open(open_console);
VVV_exit(1);
}
else if (invalid_partial_arg > 0)
{
vlog_error("%s option requires one argument.", argv[invalid_partial_arg]);
keep_console_open(open_console);
VVV_exit(1);
}

if (print_version)
{
/* Just print the version and exit. No vlogging. */
puts(
"VVVVVV " RELEASE_VERSION
#ifdef MAKEANDPLAY
" [M&P]"
#endif
);
#ifdef INTERIM_VERSION_EXISTS
puts(COMMIT_DATE);
puts(INTERIM_COMMIT);
puts(BRANCH_NAME);
#endif
keep_console_open(open_console);
VVV_exit(0);
}
else if (print_addresses)
{
printf("cl : %p\n", (void*) &cl);
printf("ed : %p\n", (void*) &ed);
printf("game : %p\n", (void*) &game);
printf("gameScreen : %p\n", (void*) &gameScreen);
printf("graphics : %p\n", (void*) &graphics);
printf("help : %p\n", (void*) &help);
printf("key : %p\n", (void*) &key);
printf("map : %p\n", (void*) &map);
printf("music : %p\n", (void*) &music);
printf("obj : %p\n", (void*) &obj);
printf("script : %p\n", (void*) &script);

keep_console_open(open_console);
VVV_exit(0);
}

SDL_SetHintWithPriority(SDL_HINT_IME_SHOW_UI, "1", SDL_HINT_OVERRIDE);

/* We already do the button swapping in ButtonGlyphs, disable SDL's swapping */
Expand Down Expand Up @@ -774,6 +815,7 @@ int main(int argc, char *argv[])
cl.ListOfMetaData.push_back(meta);
} else {
vlog_error("Level not found");
keep_console_open(open_console);
VVV_exit(1);
}
}
Expand Down
Loading