Use atexit() to wait for key press at program ternination.
Idea by polluks.
This commit is contained in:
@@ -32,6 +32,13 @@ static struct __iocb *findfreeiocb(void)
|
|||||||
return NULL;
|
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)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char *filename, *x;
|
char *filename, *x;
|
||||||
@@ -43,10 +50,10 @@ int main(int argc, char **argv)
|
|||||||
struct __iocb *iocb = findfreeiocb();
|
struct __iocb *iocb = findfreeiocb();
|
||||||
int iocb_num;
|
int iocb_num;
|
||||||
|
|
||||||
|
atexit(exitfn);
|
||||||
|
|
||||||
if (! iocb) {
|
if (! iocb) {
|
||||||
fprintf(stderr, "couldn't find a free iocb\n");
|
fprintf(stderr, "couldn't find a free iocb\n");
|
||||||
if (! _is_cmdline_dos())
|
|
||||||
cgetc();
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
iocb_num = (iocb - &IOCB) * 16;
|
iocb_num = (iocb - &IOCB) * 16;
|
||||||
@@ -59,16 +66,12 @@ int main(int argc, char **argv)
|
|||||||
printf("\n");
|
printf("\n");
|
||||||
if (! x) {
|
if (! x) {
|
||||||
printf("empty filename, exiting...\n");
|
printf("empty filename, exiting...\n");
|
||||||
if (! _is_cmdline_dos())
|
|
||||||
cgetc();
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (*x && *(x + strlen(x) - 1) == '\n')
|
if (*x && *(x + strlen(x) - 1) == '\n')
|
||||||
*(x + strlen(x) - 1) = 0;
|
*(x + strlen(x) - 1) = 0;
|
||||||
if (! strlen(x)) { /* empty filename */
|
if (! strlen(x)) { /* empty filename */
|
||||||
printf("empty filename, exiting...\n");
|
printf("empty filename, exiting...\n");
|
||||||
if (! _is_cmdline_dos())
|
|
||||||
cgetc();
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
filename = x;
|
filename = x;
|
||||||
@@ -84,8 +87,6 @@ int main(int argc, char **argv)
|
|||||||
buffer = malloc(buflen);
|
buffer = malloc(buflen);
|
||||||
if (! buffer) {
|
if (! buffer) {
|
||||||
fprintf(stderr, "cannot alloc %ld bytes -- aborting...\n", (long)buflen);
|
fprintf(stderr, "cannot alloc %ld bytes -- aborting...\n", (long)buflen);
|
||||||
if (! _is_cmdline_dos())
|
|
||||||
cgetc();
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -97,8 +98,6 @@ int main(int argc, char **argv)
|
|||||||
if (! file) {
|
if (! file) {
|
||||||
free(buffer);
|
free(buffer);
|
||||||
fprintf(stderr, "cannot open '%s': %s\n", filename, strerror(errno));
|
fprintf(stderr, "cannot open '%s': %s\n", filename, strerror(errno));
|
||||||
if (! _is_cmdline_dos())
|
|
||||||
cgetc();
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,8 +110,6 @@ int main(int argc, char **argv)
|
|||||||
file_err:
|
file_err:
|
||||||
fclose(file);
|
fclose(file);
|
||||||
free(buffer);
|
free(buffer);
|
||||||
if (! _is_cmdline_dos())
|
|
||||||
cgetc();
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (filen > 32767l) {
|
if (filen > 32767l) {
|
||||||
@@ -143,8 +140,6 @@ int main(int argc, char **argv)
|
|||||||
if (regs.y != 1) {
|
if (regs.y != 1) {
|
||||||
fprintf(stderr, "CIO call to open cassette returned %d\n", regs.y);
|
fprintf(stderr, "CIO call to open cassette returned %d\n", regs.y);
|
||||||
free(buffer);
|
free(buffer);
|
||||||
if (! _is_cmdline_dos())
|
|
||||||
cgetc();
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,8 +162,6 @@ int main(int argc, char **argv)
|
|||||||
regs.pc = 0xe456; /* CIOV */
|
regs.pc = 0xe456; /* CIOV */
|
||||||
_sys(®s);
|
_sys(®s);
|
||||||
|
|
||||||
if (! _is_cmdline_dos())
|
|
||||||
cgetc();
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,14 +176,10 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
if (regs.y != 1) {
|
if (regs.y != 1) {
|
||||||
fprintf(stderr, "CIO call to close cassette returned %d\n", regs.y);
|
fprintf(stderr, "CIO call to close cassette returned %d\n", regs.y);
|
||||||
if (! _is_cmdline_dos())
|
|
||||||
cgetc();
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* all is fine */
|
/* all is fine */
|
||||||
printf("success\n");
|
printf("success\n");
|
||||||
if (! _is_cmdline_dos())
|
|
||||||
cgetc();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user