Get rid of command line args
With new `main` it's no longer needed to collect argc/argv from cmdline.
This commit is contained in:
parent
0672161a47
commit
bc8db9e8c2
|
@ -9,8 +9,6 @@ add_executable(fallout2-ce WIN32
|
|||
"src/actions.h"
|
||||
"src/animation.cc"
|
||||
"src/animation.h"
|
||||
"src/args.cc"
|
||||
"src/args.h"
|
||||
"src/art.cc"
|
||||
"src/art.h"
|
||||
"src/audio_file.cc"
|
||||
|
|
77
src/args.cc
77
src/args.cc
|
@ -1,77 +0,0 @@
|
|||
#include "args.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
// 0x4E3B90
|
||||
void argsInit(CommandLineArguments* commandLineArguments)
|
||||
{
|
||||
if (commandLineArguments != NULL) {
|
||||
commandLineArguments->argc = 0;
|
||||
commandLineArguments->argv = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// 0x4E3BA4
|
||||
bool argsParse(CommandLineArguments* commandLineArguments, int argc, char* argv[])
|
||||
{
|
||||
const char* delim = " \t";
|
||||
|
||||
commandLineArguments->argc = argc;
|
||||
commandLineArguments->argv = (char**)malloc(sizeof(*commandLineArguments->argv) * argc);
|
||||
if (commandLineArguments->argv == NULL) {
|
||||
argsFree(commandLineArguments);
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int arg = 0; arg < argc; arg++) {
|
||||
commandLineArguments->argv[arg] = NULL;
|
||||
}
|
||||
|
||||
// Copy program name into argv[0].
|
||||
char moduleFileName[MAX_PATH];
|
||||
int moduleFileNameLength = GetModuleFileNameA(NULL, moduleFileName, MAX_PATH);
|
||||
if (moduleFileNameLength == 0) {
|
||||
argsFree(commandLineArguments);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (moduleFileNameLength >= MAX_PATH) {
|
||||
moduleFileNameLength = MAX_PATH - 1;
|
||||
}
|
||||
|
||||
moduleFileName[moduleFileNameLength] = '\0';
|
||||
|
||||
commandLineArguments->argv[0] = strdup(moduleFileName);
|
||||
if (commandLineArguments->argv[0] == NULL) {
|
||||
argsFree(commandLineArguments);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Copy arguments from command line into argv.
|
||||
for (int i = 1; i < argc; i++) { // skip argv[0]
|
||||
commandLineArguments->argv[i] = strdup(argv[i]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// 0x4E3D3C
|
||||
void argsFree(CommandLineArguments* commandLineArguments)
|
||||
{
|
||||
if (commandLineArguments->argv != NULL) {
|
||||
// NOTE: Compiled code is slightly different - it decrements argc.
|
||||
for (int index = 0; index < commandLineArguments->argc; index++) {
|
||||
if (commandLineArguments->argv[index] != NULL) {
|
||||
free(commandLineArguments->argv[index]);
|
||||
}
|
||||
}
|
||||
free(commandLineArguments->argv);
|
||||
}
|
||||
|
||||
commandLineArguments->argc = 0;
|
||||
commandLineArguments->argv = NULL;
|
||||
}
|
15
src/args.h
15
src/args.h
|
@ -1,15 +0,0 @@
|
|||
#ifndef ARGS_H
|
||||
#define ARGS_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct CommandLineArguments {
|
||||
int argc;
|
||||
char** argv;
|
||||
} CommandLineArguments;
|
||||
|
||||
void argsInit(CommandLineArguments* commandLineArguments);
|
||||
bool argsParse(CommandLineArguments* commandLineArguments, int argc, char* argv[]);
|
||||
void argsFree(CommandLineArguments* commandLineArguments);
|
||||
|
||||
#endif /* ARGS_H */
|
|
@ -1,6 +1,5 @@
|
|||
#include "win32.h"
|
||||
|
||||
#include "args.h"
|
||||
#include "core.h"
|
||||
#include "main.h"
|
||||
#include "window_manager.h"
|
||||
|
@ -25,18 +24,12 @@ HMODULE gDSoundDLL = NULL;
|
|||
// 0x4DE700
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
CommandLineArguments args;
|
||||
|
||||
_GNW95_mutex = CreateMutexA(0, TRUE, "GNW95MUTEX");
|
||||
if (GetLastError() == ERROR_SUCCESS) {
|
||||
SDL_ShowCursor(SDL_DISABLE);
|
||||
if (_LoadDirectX()) {
|
||||
argsInit(&args);
|
||||
if (argsParse(&args, argc, argv)) {
|
||||
gProgramIsActive = true;
|
||||
falloutMain(args.argc, args.argv);
|
||||
argsFree(&args);
|
||||
}
|
||||
falloutMain(argc, argv);
|
||||
}
|
||||
CloseHandle(_GNW95_mutex);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue