return NULL;
}
+static void exitfn(void)
+{
+ /* if DOS will automatically clear the screen, after the program exits, wait for a keypress... */
+ if (! _is_cmdline_dos())
+ cgetc();
+}
+
int main(int argc, char **argv)
{
char *filename, *x;
struct __iocb *iocb = findfreeiocb();
int iocb_num;
+ atexit(exitfn);
+
if (! iocb) {
fprintf(stderr, "couldn't find a free iocb\n");
- if (! _is_cmdline_dos())
- cgetc();
return 1;
}
iocb_num = (iocb - &IOCB) * 16;
printf("\n");
if (! x) {
printf("empty filename, exiting...\n");
- if (! _is_cmdline_dos())
- cgetc();
return 1;
}
if (*x && *(x + strlen(x) - 1) == '\n')
*(x + strlen(x) - 1) = 0;
if (! strlen(x)) { /* empty filename */
printf("empty filename, exiting...\n");
- if (! _is_cmdline_dos())
- cgetc();
return 1;
}
filename = x;
buffer = malloc(buflen);
if (! buffer) {
fprintf(stderr, "cannot alloc %ld bytes -- aborting...\n", (long)buflen);
- if (! _is_cmdline_dos())
- cgetc();
return 1;
}
}
if (! file) {
free(buffer);
fprintf(stderr, "cannot open '%s': %s\n", filename, strerror(errno));
- if (! _is_cmdline_dos())
- cgetc();
return 1;
}
file_err:
fclose(file);
free(buffer);
- if (! _is_cmdline_dos())
- cgetc();
return 1;
}
if (filen > 32767l) {
if (regs.y != 1) {
fprintf(stderr, "CIO call to open cassette returned %d\n", regs.y);
free(buffer);
- if (! _is_cmdline_dos())
- cgetc();
return 1;
}
regs.pc = 0xe456; /* CIOV */
_sys(®s);
- if (! _is_cmdline_dos())
- cgetc();
return 1;
}
if (regs.y != 1) {
fprintf(stderr, "CIO call to close cassette returned %d\n", regs.y);
- if (! _is_cmdline_dos())
- cgetc();
return 1;
}
/* all is fine */
printf("success\n");
- if (! _is_cmdline_dos())
- cgetc();
return 0;
}