X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f996b,fc8ebd0c12964164 X-Google-Attributes: gidf996b,public X-Google-Thread: fd588,fc8ebd0c12964164 X-Google-Attributes: gidfd588,public X-Google-ArrivalTime: 1994-05-10 03:22:55 PST Newsgroups: alt.ascii-art,alt.ascii-art.animation Path: gmd.de!nntp.gmd.de!xlink.net!howland.reston.ans.net!pipex!uknet!festival!leeds.ac.uk!news From: cszwt2@scs.leeds.ac.uk (Wills Towle) Subject: Viewer Utility (fixed -D option) Originator: cszwt2@scs.leeds.ac.uk Message-ID: <1994May10.090508.25307@leeds.ac.uk> Sender: news@leeds.ac.uk NNTP-Posting-Host: csgi27 Organization: Slightly More Than Last Time Date: Tue, 10 May 1994 09:05:08 GMT References: <1994May9.202859.23865@leeds.ac.uk> Lines: 280 Here is the correct version 1.2 of my (unix) viewer utility, vu. It can now handle multiple files, and each file can have a unique combination of vu's operations on it (count height & width on/off, delays during file display, show file on/off). Vu can also now have text piped into it. Vu will probably need some amendments (to the pipe handling, principally - you may also be missing some .h files, for which I can tell you what they are for, but otherwise can't help you) if you wish to compile it for use on a PC. It might even require the files to be converted to DOS text format..... :::::: :: William "Wills" Towle : cszwt2@scs.leeds.ac.uk (cszwt2%scs@gps.leeds.ac.uk) :: "Keyboard not responding. Press ENTER to continue" - PC error message Here is the C source code; just cut-and-paste. -----x8-----start vu.c----- #include #include #include #include #include #include #include #define WAIT 500 typedef enum {FALSE,TRUE} bool; /* Couple of global variables (yuk!) */ char escBuf[10]; int escBufPos; extern char* optarg; extern int optind; char tempFile[30]; void ifbodge(int arg,int args) { if (arg==args) { printf ("%s\n", "vu: Missing filename(s)"); exit(0); } } void do_cposch(int* lines, int* width, int* lwidth) { int nwidth,eBpos; eBpos = 0; while (isdigit(escBuf[eBpos])) eBpos++; if (escBuf[eBpos] == ';') { eBpos++; nwidth = 0; while (isdigit(escBuf[eBpos])) { nwidth = ((nwidth)*10) + (escBuf[eBpos]-'0'); eBpos++; } nwidth--; *lwidth = nwidth; if (nwidth>*width) *width = nwidth; } } /* Unused... results not constant w.r.t usec variable */ void delay(int usec) { struct timeval timeout; if(usec == 0) return; timeout.tv_sec = usec / 1000000; timeout.tv_usec = usec; select(1, NULL, NULL, NULL, &timeout); } void readfile(char* name, bool count, bool list, int pause) { FILE* inFile; char byte; bool openFail,escape,escOSB /* ESCAPE OPEN-SQUARE-BRACKET */; int lines,width,lwidth,i; if (isatty(fileno(stdin))) system ("stty -echo"); openFail = FALSE; if (count) if ( (inFile = fopen(name,"rb")) == NULL ) { printf ("%s %s\n", "vu: Can't open file", name); openFail = TRUE; } else { lines = 0; width = 0; lwidth = 0; while (fread(&byte,sizeof(char),1,inFile)) { switch (byte) { case 9: /* tab */ if (!escape) { while ( lwidth%8 ) lwidth++; if ( (lwidth) > width) width = lwidth; break; } case 10: /* newline */ escape = FALSE; lines++; lwidth = 0; break; case 27: /* escape */ escape = TRUE; fread(&byte,sizeof(char),1,inFile); if (byte='[') escOSB = TRUE; else escOSB = FALSE; break; default: if (!escape) { if ( (++lwidth) > width) width = lwidth; } else { if (escBufPos<=10) { escBuf[escBufPos] = byte; escBufPos++; } if (escOSB && isalpha(byte)) { escape = FALSE; if ( (byte=='H') || (byte == 'f') ) do_cposch(&lines,&width,&lwidth); } if (!escOSB && isdigit(byte)) escape = FALSE; } } } /* end of file. */ printf ("----- vu: file stats\n"); printf ("File : %s\n", name); printf ("Width: %d\n", width); printf ("Lines: %d\n", lines); printf ("-----\n"); if (list && count && isatty(fileno(stdout))) { printf ("(RETURN:)"); do {scanf("%c",&byte);} while (byte!=10); printf ("\n"); } } if (list && !openFail) if ( (inFile = fopen(name,"rb")) == NULL ) { printf ("%s %s\n", "vu: Can't open file", name); } else { lines = 0; width = 0; lwidth = 0; while (fread(&byte,sizeof(char),1,inFile)) { switch (byte) { case 9: /* tab */ printf ("\t"); break; case 10: /* newline */ printf ("\n"); break; default: printf ("%c", byte); break; } for (i = 0; i [...]"); printf ("\n%s\n\t%s\n\t%s\n\t%s\n\t%s\n%s\n", "Options are:", "-c (-C) : dont (do) work out file size (default: do)", "-d : add delay, duration n", "-l (-L) : dont (do) list the actual file (default: do)", "-D : use default options (-C -L -d 0)", "Use - on command line to read from a pipe"); exit(0); } while (optind