clean up cliopts
This commit is contained in:
parent
2bd840a299
commit
952495ae08
|
@ -1,4 +1,7 @@
|
||||||
#include "cliopts.h"
|
#include "cliopts.h"
|
||||||
|
#include "configfile.h"
|
||||||
|
#include "pc_main.h"
|
||||||
|
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -6,53 +9,45 @@
|
||||||
|
|
||||||
struct PCCLIOptions gCLIOpts;
|
struct PCCLIOptions gCLIOpts;
|
||||||
|
|
||||||
void parse_cli_opts(int argc, char* argv[])
|
static void print_help(void) {
|
||||||
{
|
printf("Super Mario 64 PC Port\n");
|
||||||
// Initialize options with false values.
|
printf("%-20s\tSkips the Peach and Castle intro when starting a new game.\n", "--skip-intro");
|
||||||
gCLIOpts.SkipIntro = 0;
|
printf("%-20s\tStarts the game in full screen mode.\n", "--fullscreen");
|
||||||
gCLIOpts.FullScreen = 0;
|
printf("%-20s\tStarts the game in windowed mode.\n", "--windowed");
|
||||||
gCLIOpts.ConfigFile = malloc(31);
|
printf("%-20s\tSaves the configuration file as CONFIGNAME.\n", "--configfile CONFIGNAME");
|
||||||
strncpy(gCLIOpts.ConfigFile, "sm64config.txt", strlen("sm64config.txt"));
|
}
|
||||||
gCLIOpts.ConfigFile[strlen("sm64config.txt")] = '\0';
|
|
||||||
|
void parse_cli_opts(int argc, char* argv[]) {
|
||||||
// Scan arguments for options
|
// Initialize options with false values.
|
||||||
if (argc > 1)
|
memset(&gCLIOpts, 0, sizeof(gCLIOpts));
|
||||||
{
|
strncpy(gCLIOpts.ConfigFile, CONFIGFILE_DEFAULT, sizeof(gCLIOpts.ConfigFile));
|
||||||
int i;
|
|
||||||
for (i = 1; i < argc; i++)
|
for (int i = 1; i < argc; i++) {
|
||||||
{
|
if (strcmp(argv[i], "--skip-intro") == 0) // Skip Peach Intro
|
||||||
if (strcmp(argv[i], "--skip-intro") == 0) // Skip Peach Intro
|
gCLIOpts.SkipIntro = 1;
|
||||||
gCLIOpts.SkipIntro = 1;
|
|
||||||
|
else if (strcmp(argv[i], "--fullscreen") == 0) // Open game in fullscreen
|
||||||
if (strcmp(argv[i], "--fullscreen") == 0) // Open game in fullscreen
|
gCLIOpts.FullScreen = 1;
|
||||||
gCLIOpts.FullScreen = 1;
|
|
||||||
|
else if (strcmp(argv[i], "--windowed") == 0) // Open game in windowed mode
|
||||||
if (strcmp(argv[i], "--windowed") == 0) // Open game in windowed mode
|
gCLIOpts.FullScreen = 2;
|
||||||
gCLIOpts.FullScreen = 2;
|
|
||||||
|
// Print help
|
||||||
if (strcmp(argv[i], "--help") == 0) // Print help
|
else if (strcmp(argv[i], "--help") == 0) {
|
||||||
{
|
print_help();
|
||||||
printf("Super Mario 64 PC Port\n");
|
game_exit();
|
||||||
printf("%-20s\tSkips the Peach and Castle intro when starting a new game.\n", "--skip-intro");
|
}
|
||||||
printf("%-20s\tStarts the game in full screen mode.\n", "--fullscreen");
|
|
||||||
printf("%-20s\tStarts the game in windowed mode.\n", "--windowed");
|
else if (strcmp(argv[i], "--configfile") == 0) {
|
||||||
printf("%-20s\tSaves the configuration file as CONFIGNAME.\n", "--configfile CONFIGNAME");
|
if (i+1 < argc) {
|
||||||
exit(0);
|
const unsigned int arglen = strlen(argv[i+1]);
|
||||||
}
|
if (arglen >= sizeof(gCLIOpts.ConfigFile)) {
|
||||||
|
fprintf(stderr, "Configuration file supplied has a name too long.\n");
|
||||||
if (strncmp(argv[i], "--configfile", strlen("--configfile")) == 0)
|
} else {
|
||||||
{
|
strncpy(gCLIOpts.ConfigFile, argv[i+1], arglen);
|
||||||
if (i+1 < argc)
|
gCLIOpts.ConfigFile[arglen] = '\0';
|
||||||
{
|
}
|
||||||
if (strlen(argv[i]) > 30) {
|
}
|
||||||
fprintf(stderr, "Configuration file supplied has a name too long.\n");
|
}
|
||||||
} else {
|
}
|
||||||
memset(gCLIOpts.ConfigFile, 0, 30);
|
|
||||||
strncpy(gCLIOpts.ConfigFile, argv[i+1], strlen(argv[i+1]));
|
|
||||||
gCLIOpts.ConfigFile[strlen(argv[i+1])] = '\0';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
#include "sm64.h"
|
#ifndef _CLIOPTS_H
|
||||||
|
#define _CLIOPTS_H
|
||||||
|
|
||||||
struct PCCLIOptions
|
struct PCCLIOptions {
|
||||||
{
|
unsigned int SkipIntro;
|
||||||
u8 SkipIntro;
|
unsigned int FullScreen;
|
||||||
u8 FullScreen;
|
char ConfigFile[1024];
|
||||||
char * ConfigFile;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern struct PCCLIOptions gCLIOpts;
|
extern struct PCCLIOptions gCLIOpts;
|
||||||
|
|
||||||
void parse_cli_opts(int argc, char* argv[]);
|
void parse_cli_opts(int argc, char* argv[]);
|
||||||
|
|
||||||
|
#endif // _CLIOPTS_H
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#define CONFIGFILE_DEFAULT "sm64config.txt"
|
||||||
|
|
||||||
#define MAX_BINDS 3
|
#define MAX_BINDS 3
|
||||||
#define MAX_VOLUME 127
|
#define MAX_VOLUME 127
|
||||||
#define VOLUME_SHIFT 7
|
#define VOLUME_SHIFT 7
|
||||||
|
|
Loading…
Reference in New Issue