home *** CD-ROM | disk | FTP | other *** search
- /*
- ┌────────────────────────────────────────────────────────────────────────────┐
- │ Title : view.c │
- │ Purpose : View a file on the screen but on exit, return the users screen │
- │ to what it originally was including the command line which │
- │ invoked this program. │
- │ USAGE: View <filename> │
- │ Written by Jack Zucker - 75766,1336 301-794-5950 on 02-03-1986 │
- └────────────────────────────────────────────────────────────────────────────┘
- */
-
- #include <jaz.h> /* misc macros */
- #include <jzscreen.h> /* window defs */
- #include <gscreen.h> /* global window constants */
- #include <stdio.h> /* standard io defs */
-
- #define max(x,y) (x > y ? x : y)
- #define min(x,y) (x < y ? x : y)
-
- #define MAXLINES 2000 /* max lines in file */
- #define PGUP 73
- #define PGDN 81
- #define HOME 71
- #define END 79
- #define DARR 80
- #define UARR 72
- #define ESC 27
- #define ATTRIBUTE 31 /* video attribute for screen */
- #define TIMER 0x1C /* vector for timer interrupt */
-
- int WDONE = 0; /* flag for done with program */
- int gcount = 17; /* tic count for clock routine*/
- int clock(); /* interrupt handler for clock*/
-
- main(argc,argv)
- int argc;
- char **argv;
- {
- TWINDOW *ptr; /* pointer to window structure */
- char wbuf[256],wtemp[256],*strchr();
- int num,windex=0,wlinelen,wstart,w,wrow;
- char *pline[MAXLINES],*p; /* allocate memory for lines */
- FILE *fd;
- char *ch,chr;
- int wch;
- TVECTOR wvec; /* hold timer interrupt vector address */
-
- jzgetint(TIMER,&wvec); /* get original timer address */
-
- ptr = jzappend(&g_header,7,0,0,0x18,0x4f,1); /* save original window */
-
- if (argc < 2) {
- printf("\nVIEW... by Jack A. Zucker @794-5950 | 794-8763 | 75766,1336");
- exitpgm(ptr,"USAGE: View <filename>");
- }
-
- if (! (fd = fopen(argv[1],"r"))) {
- sprintf(wbuf,"Can't open %s",argv[1]);
- exitpgm(ptr,wbuf);
- }
-
- jzloccur(24,0);
- printf("Reading Line# ");
- jzclreol(0x18,0x0e,7);
-
- while ( (ch = fgets(wbuf,255,fd)) ) { /* read file - display line# */
- tabtosp(wbuf,wtemp);
- wtemp[79] = '\0';
- p = strchr(wtemp,'\n'); /* get rid of new lines */
- if (p) *p = '\0'; /* get rid of new line */
- pline[windex] = (char *) malloc(strlen(wtemp)+1); /* memory for line */
- jzloccur(24,14);
- printf("%04d",windex+1);
- strcpy(pline[windex],wtemp); /* copy line into list */
- ++windex;
- }
- fclose(fd);
-
- windex--; /* get last line number */
- wstart = 0;
-
- jzclreol(0x18,0,7);
- jzloccur(24,20);
- printf("ESC | UARR | DARR | HOME | END | PGUP | PGDN");
-
- jzinsint(TIMER,clock); /* install our interrupt handler */
-
- dispscreen(pline,wstart,windex);
- do {
- jzloccur(24,0); /* print line # of 1st line */
- printf("Line# %04d",wstart+1);
- if ((chr = jzinkey(&wch)))
- switch (chr) { /* look for esc key - end */
- case ESC : WDONE = 1;
- }
- else
- switch(wch) {
- case PGUP :
- wstart = max(0,wstart-24);
- dispscreen(pline,wstart,windex);
- break;
- case PGDN :
- wstart = max(min(windex-23,wstart+24),0);
- dispscreen(pline,wstart,windex);
- break;
- case UARR :
- if (wstart) {
- wstart = max(0,wstart-1);
- jzscrldn(0,0x174f,1,ATTRIBUTE); /* clear screen window */
- jzscrprn(pline[wstart],0,0,ATTRIBUTE);
- }
- break;
- case DARR :
- if (windex - (wstart + 23) > 0) {
- wstart = max(min(windex-23,wstart+1),0);
- jzscrlup(0,0x174f,1,ATTRIBUTE); /* clear screen window */
- jzscrprn(pline[wstart+23],23,0,ATTRIBUTE);
- }
- break;
- case HOME :
- wstart = 0;
- dispscreen(pline,wstart,windex);
- break;
- case END :
- wstart = max(0,windex-23);
- dispscreen(pline,wstart,windex);
- break;
- }
- } while (! WDONE);
-
- jzsetint(TIMER,wvec); /* restore original interrupt handler */
-
- jzloccur(ptr->row-2,ptr->col); /* back to original pos */
- jzrstwnd(ptr); /* restore users window */
-
- }
-
- exitpgm(fptr,fmsg)
- TWINDOW *fptr;
- char *fmsg;
- {
- printf("\n%s",fmsg); /* print message */
- printf("\nHit <ENTER> to continue...");
- do ; while (getch() != 13); /* loop 'til <ENTER> */
- jzloccur(fptr->row-2,fptr->col); /* back to original pos */
- jzrstwnd(fptr); /* restore users window */
- exit(1);
- }
-
- dispscreen(fline , fstart , findex)
- char **fline;
- int fstart,findex;
- {
- int wrow,w;
-
- jzscrlup(0,0x174f,0,ATTRIBUTE); /* clear screen window */
- wrow = 0;
- for(w = fstart; w <= fstart + 23 ; w ++)
- if (w > findex) return;
- else jzscrprn(fline[w],wrow++,0,ATTRIBUTE); /* bios write str */
- }
-
- clock()
- {
- char wstr[9];
- if (gcount >= 18) {
- jzbiostm(wstr);
- jzscrprn(wstr,24,71,MAGENTA);
- gcount = 0;
- }
- else
- gcount ++;
- }
-
-