Skip to content

Commit

Permalink
Add _parse_options() to abstraction_vstudio.h
Browse files Browse the repository at this point in the history
  • Loading branch information
pzembrod committed Jan 14, 2024
1 parent 092721b commit c2f4a3c
Showing 1 changed file with 83 additions and 6 deletions.
89 changes: 83 additions & 6 deletions RunCPM/abstraction_vstudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -486,10 +486,92 @@ uint32 _HardwareIn(const uint32 Port) {
/* Host initialization functions */
/*===============================================================================*/

void _host_init(int argc, char* argv[]) {
#ifdef STREAMIO
static void _abort_if_kbd_eof() {
}

static void _file_failure_exit(char *argv[], char* fmt, char* filename)
{
fprintf(stderr, "%s: ", argv[0]);
fprintf(stderr, fmt, filename);
if (errno) {
fprintf(stderr, ": %s", strerror(errno));
}
fprintf(stderr, "\n");
exit(EXIT_FAILURE);
}

static void _usage(char *argv[]) {
fprintf(stderr,
"RunCPM - an emulator to run CP/M programs on modern hosts\n"
"usage: %s [-i input_file] [-o output_file] [-s]\n", argv[0]);
fprintf(stderr,
" -i input_file: console input will be read from the file "
"with the\n given name. "
"After input file's EOF, further console input\n will be read "
"from the keyboard.\n");
fprintf(stderr,
" -o output_file: console output will be written to the file "
"with the\n given name, in addition to the screen.\n");
fprintf(stderr,
" -s: console input and output is connected directly to "
"stdin and stdout.\n");
}

#define SET_OPTARG ++i; if (i >= argc) {++errflg; break;} optarg = argv[i];

static void _parse_options(int argc, char *argv[]) {
int errflg = 0;
char *optarg;
for (int i = 1; i < argc && errflg == 0; ++i) {
if (strcmp("-i", argv[i]) == 0) {
/* ++i;
if (i >= argc) {
++errflg;
break;
}
optarg = argv[i]; */
SET_OPTARG
streamInputFile = fopen(optarg, "r");
if (NULL == streamInputFile) {
_file_failure_exit(argv,
"error opening console input file %s", optarg);
}
streamInputActive = TRUE;
continue;
}
if (strcmp("-o", argv[i]) == 0) {
SET_OPTARG
streamOutputFile = fopen(optarg, "w");
if (NULL == streamOutputFile) {
_file_failure_exit(argv,
"error opening console output file %s", optarg);
}
continue;
}
if (strcmp("-s", argv[i]) == 0) {
streamInputFile = stdin;
streamOutputFile = stdout;
streamInputActive = TRUE;
consoleOutputActive = FALSE;
continue;
}
fprintf(stderr,
"Unrecognized option: '%s'\n", argv[i]);
errflg++;
}
if (errflg) {
_usage(argv);
exit(EXIT_FAILURE);
}
}
#endif

void _host_init(int argc, char* argv[]) {
#ifdef STREAMIO
_parse_options(argc, argv);
#endif
}

/* Console abstraction functions */
/*===============================================================================*/
Expand All @@ -512,11 +594,6 @@ void _console_init(void) {
void _console_reset(void) {
}

#ifdef STREAMIO
static void _abort_if_kbd_eof() {

}
#endif

/* Implemented by conio.h
int _kbhit(void)
Expand Down

0 comments on commit c2f4a3c

Please sign in to comment.