Viewer utility (for pics and .VTs)
Here is 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) 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 : csz...@scs.leeds.ac.uk (csz...@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 <stdio.h>
#include <ctype.h>
#include <getopt.h>
#include <sys/types.h>
#include <signal.h>
#include <sys/time.h>
#include <unistd.h>
#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 isTTY, bool count, bool list, int pause)
{
FILE* inFile;
char byte;
bool openFail,escape,escOSB /* ESCAPE OPEN-SQUARE-BRACKET */;
int lines,width,lwidth,i;
if (isTTY)
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 && isTTY)
{
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<pause*WAIT; i++);
} /* end of file. */
}
if (isTTY)
system ("stty echo");
}
void read_stdin()
{
char byte;
FILE *outFile;
strcpy(tempFile,tempnam("/tmp/", "vu"));
outFile = fopen(tempFile, "wb");
while (fread(&byte,sizeof(char),1,stdin))
{
fwrite(&byte,sizeof(char),1,outFile);
} /* end of file. */
fclose(outFile);
}
void main(int argc,char** argv)
{
/* Option variables */
int arg,i,pause;
bool list=TRUE, count=TRUE;
if (argc == 1)
{
printf ("%s\n%s %s %s\n",
"vu (v1.2) -- by Wm.Towle",
"Usage:", argv[0], "[options] < filename | - > [...]");
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 <n> : 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<argc)
{
while ( (arg=getopt(argc,argv, "cCd:lL")) != -1 )
switch (arg)
{
case 'c':
case 'C':
count = isupper(arg);
ifbodge(optind,argc);
break;
case 'd':
i=0; pause=0;
while ( isdigit(optarg[i]) )
{
pause = (pause*10) + (optarg[i] - '0');
i++;
}
ifbodge(optind,argc);
break;
case 'D':
count=TRUE;
list=TRUE;
pause=0;
break;
case 'l':
case 'L':
list = isupper(arg);
ifbodge(optind,argc);
break;
default: printf("%s %d\n","Bad option", optind<argc);
/* shouldn't see this */
};
if (optind<=argc)
{
if (strcmp(argv[optind],"-")==0)
{
read_stdin();
readfile(tempFile, isatty(fileno(stdin)),
count,list,pause);
unlink(tempFile);
}
else
readfile(argv[optind], FALSE, count,list,pause);
optind++;
}
}
}
-----x8-----end vu.c-----
Vu is public domain. No harm should come to your files and
filesystem through its use as a file-to-screen viewer, but I
cannot accept responsibility for loss of files/system damage
caused by careless use.
Original message headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f996b,fc8ebd0c12964164,start X-Google-Attributes: gidf996b,public X-Google-Thread: fd588,fc8ebd0c12964164,start X-Google-Attributes: gidfd588,public X-Google-ArrivalTime: 1994-05-09 16:15:53 PST Newsgroups: alt.ascii-art,alt.ascii-art.animation Path: gmd.de!nntp.gmd.de!xlink.net!howland.reston.ans.net!EU.net!uknet!festival!leeds.ac.uk!news From: csz...@scs.leeds.ac.uk (W Towle) Subject: Viewer utility (for pics and .VTs) Originator: csz...@scs.leeds.ac.uk Message-ID: <199...@leeds.ac.uk> Sender: new...@leeds.ac.uk NNTP-Posting-Host: csgi48 Organization: Very Little Date: Mon, 9 May 1994 20:28:59 GMT Lines: 278
About this message.
This message was posted publicly to the newsgroup
alt.ascii-art
in 1994 and is mirrored here unchanged as part of the Historic Archives – only email addresses are masked.
The artwork and text belong to their original authors: if you copy a piece, keep the artist's initials or signature intact and credit them where you can.
Are you the author? Contact us to get your posts attributed, connected to your artist profile, or removed.