/* Most (c) Alex Tweedly 1986 */ /* switch ACC defines if an accessory is required */ #define ACC 0 /**** INCLUDE FILES ****/ #include #include /* Only define those OS and GEM items used. */ extern long bios(); extern long xbios(); extern long gemdos(); /* BIOS (trap13) */ #define Bconout(a,b) bios(3,a,b) /* XBIOS (trap14) */ #define Physbase() xbios(2) #define Logbase() xbios(3) #define Getrez() (int)xbios(4) #define Setscreen(a,b,c) xbios(5,a,b,c) /* GEMDOS (trap1) */ #define Cconin() gemdos(0x1) #define Cconout(a) gemdos(0x2,a) #define AC_OPEN 40 #define AC_CLOSE 41 /* General purpose defines */ #define TRUE 1 #define FALSE 0 #define FOREVER for (;;) /* program specific */ /* allocation boundary for graphic pages */ #define NBYTE (512) #define NDIV (NBYTE-1) FILE *in; #define LINELEN 80 #define NOCHANGE -1L #define SAMEREZ -1 #if ACC /*********************************************************************/ /* GLOBAL VARIABLES */ /*********************************************************************/ extern int gl_apid; int gl_hchar; int gl_wchar; int gl_wbox; int gl_hbox; /* system sizes */ int menu_id ; /* our menu id */ int phys_handle; /* physical workstation handle */ int handle; /* virtual workstation handle */ int wi_handle; /* window handle */ int top_window; /* handle of topped window */ int xdesk,ydesk,hdesk,wdesk; int xold,yold,hold,wold; int xwork,ywork,hwork,wwork; /* desktop and work areas */ int msgbuff[8]; /* event message buffer */ int contrl[12]; int intin[128]; int ptsin[128]; int intout[128]; int ptsout[128]; /* storage wasted for idiotic bindings */ int work_in[11]; /* Input to GSX parameter array */ int work_out[57]; /* Output from GSX parameter array */ int pxyarray[10]; /* input point array */ /* end of them */ #endif char *sc0, *sc1, *sc2; char filename[20]; #if ACC main() { appl_init(); menu_id=menu_register(gl_apid," MoST "); /* remember current 'system' page */ sc0 = (char *) Logbase(); /* * allocate two new pages - must be on a N byte boundary, but * I do not recall what N is, or where I read that. N = 512 works. */ sc1 = (char *)( ((long) (malloc(32768+NBYTE) + NBYTE ) & (~NDIV) ) ); sc2 = (char *)( ((long) (malloc(32768+NBYTE) + NBYTE ) & (~NDIV) ) ); multi(); } #else /* a TTP rather than an Accessory */ main(argc, argv) char **argv; int argc; { /* use existing system page memory */ sc0 = sc1 = (char *) Logbase(); sc2 = (char *)( ((long) (malloc(32768+NBYTE) + NBYTE ) & (~NDIV) ) ); if (argc >= 2) { strcpy( filename, argv[1] ); doit( FALSE ); } else doit( TRUE ); } #endif doit( needname ) int needname; { char *temp; int done = 0; int new_done; char reply; Setscreen(sc1, sc1, SAMEREZ); /* Clear screen */ Cconout(27); Cconout(69); if ( needname ) { /* Enable cursor */ Cconout(27); Cconout(101); cout(" Enter file name : "); cin( filename ); } in = fopen(filename, "r"); if (in == NULL) { cout(" File '"); cout( filename ); cout("' cannot be opened for reading."); Cconout(10); Cconout(13); cout("press any key to continue"); Cconin(); goto finish; } restart: done = read_page(); FOREVER { /* display screen 1, prepare to format other */ Setscreen(sc2, sc1, SAMEREZ); if ( done == 0 ) new_done = read_page(); reply = toupper( (int) Cconin() ); if ( reply == 'Q' ) break; if ( reply == 'R' ) { /* Restart */ rewind( in ); /* now we must swap screens */ temp = sc1; sc1 = sc2; sc2 = temp; goto restart; } if (done) break; /* swap screens */ temp = sc1; sc1 = sc2; sc2 = temp; done = new_done; } fclose(in); finish: /* and return to displaying the system screen */ #if ACC Setscreen(sc0, sc0, SAMEREZ); #else /* change to outputting to the system screen */ Setscreen(sc0, sc1, SAMEREZ); /* clear the system screen */ Cconout(27); Cconout(69); Setscreen(sc0, sc0, SAMEREZ); #endif return(0); } read_page() { int i; register char *p; register int c; char buf[LINELEN]; /* Clear screen */ Cconout(27); Cconout(69); for (i=0; i<=23; i++) { if ( (p = fgets( buf, LINELEN, in) ) == NULL ) { cout("--End--"); return(TRUE); } while ( (c = (int) *p++) != 0) Bconout(2, c); Cconout(13); } cout("--Again--"); return (FALSE); } cout(s) register char *s; { while (*s) Cconout(*s++); } cin(s) register char *s; { register char c; FOREVER { c = (char) Cconin(); /* if RETURN, change to terminator and exit loop */ if (c == 13) { *s++ = 0; break; } *s++ = c; } } #if ACC /****************************************************************/ /* dispatches all accessory tasks */ /****************************************************************/ multi() { int event; while (TRUE) { evnt_mesag(msgbuff); switch (msgbuff[0]) { case AC_OPEN: if (msgbuff[4] == menu_id) { doit( TRUE ); } case AC_CLOSE: if (msgbuff[3] == menu_id) { event = 1; } break; } /* switch (msgbuff[0]) */ } /* while (TRUE) */ } #endif