1
0
mirror of https://github.com/pevans/erc-c.git synced 2024-11-23 23:32:45 +00:00

Add size option, functions to get width and height

This commit is contained in:
Peter Evans 2017-12-20 17:06:03 -06:00
parent b1c146c62d
commit 609e3eea7c
3 changed files with 50 additions and 2 deletions

View File

@ -12,6 +12,7 @@ enum log_errcode {
ERR_OOM, // out of memory
ERR_OOB, // out of bounds
ERR_BADFILE,
ERR_BADOPT, // bad option (e.g. from getopt)
ERR_GFXINIT, // couldn't initialize graphics
ERR_GFXOP, // we couldn't execute a specific graphic operation
};

View File

@ -15,5 +15,8 @@ extern void option_print_help();
extern int option_read_file(int, const char *);
extern void option_set_error(const char *);
extern void option_set_input(int, FILE *);
extern int option_set_size(const char *);
extern int option_get_width();
extern int option_get_height();
#endif

View File

@ -12,6 +12,7 @@
#include <unistd.h>
#include "option.h"
#include "log.h"
/*
* These are the file inputs we may have to the system. What their
@ -32,15 +33,22 @@ static FILE *input2 = NULL;
*/
static char error_buffer[ERRBUF_SIZE] = "";
/*
* The default width and height of the window
*/
static int width = 640;
static int height = 480;
/*
* These are all of the options we allow in our long-form options. It's
* a bit faster to identify them by integer symbols than to do string
* comparisons.
*/
enum options {
HELP,
DISK1,
DISK2,
HELP,
SIZE,
};
/*
@ -50,6 +58,7 @@ static struct option long_options[] = {
{ "disk1", 1, NULL, DISK1 },
{ "disk2", 1, NULL, DISK2 },
{ "help", 0, NULL, HELP },
{ "size", 1, NULL, SIZE },
};
/*
@ -113,6 +122,12 @@ option_parse(int argc, char **argv)
// The help option should terminate normal execution
return 0;
case SIZE:
if (option_set_size(optarg) != OK) {
return 0;
}
break;
}
// We seem to have a request to load a file, so let's do so.
@ -201,5 +216,34 @@ option_print_help()
fprintf(stderr, "\
--disk1=FILE Load FILE into disk drive 1\n\
--disk2=FILE Load FILE into disk drive 2\n\
--help Print this help message\n");
--help Print this help message\n\
--size=WIDTHxHEIGHT Use WIDTH and HEIGHT for window size\n\
(only 640x480 and 800x600 are supported)\n");
}
int
option_set_size(const char *size)
{
if (strcmp(size, "640x480") == 0) {
return OK;
} else if (strcmp(size, "800x600") == 0) {
width = 800;
height = 600;
return OK;
}
snprintf(error_buffer, ERRBUF_SIZE, "Ignoring bad window size: %s", size);
return ERR_BADOPT;
}
int
option_get_width()
{
return width;
}
int
option_get_height()
{
return height;
}