Original Usenet thread from alt.ascii-art, started 9 May 1994.
Viewer utility (for pics and .VTs)
alt.ascii-art
· 2 messages · 9 May 1994 - 10 May 1994
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.
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 : 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 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<pause*WAIT; i++);
} /* end of file. */
}
if (isatty(fileno(stdin)))
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:DlL")) != -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;
ifbodge(optind,argc);
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, count,list,pause);
unlink(tempFile);
}
else
readfile(argv[optind], 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.
Related ASCII art in the Gallery
Explore these categories from our collection of 11,000+ artworks:
.------------. |\\//\\//\\//| |//\\//\\//\\| |\\//\\//\\//| |//\\//\\//\\| '------------'
_______ /` _____ `\;, /__(^===^)__\';, / ::: \ ,; | ::: | ,;' '._______.'`jgs
_ _ (o)(o)--. \../ ( )hjw m\/m--m'`--.
_ _
/` \/ `\_ _
\ /` \/ `\
'. .\ /
\/ '. .'
\/jgs __ . . __ (o.\ \/ /.o) \__\/\/__/ /O /==\ O\ (;O/ \/ \O;)
_______ |.-----.| || jgs || ||_ _|| `--)-(--` __[=== o]___ |:::::::::::|\ `-=========-`()
Make your own ASCII art
Turn images, text or 3D into ASCII, or draw your own – right in your browser.
About this thread.
These messages were posted publicly to the newsgroup
alt.ascii-art
in 1994 and are 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 one of the authors? Contact us to get your posts attributed, connected to your artist profile, or removed.
Report this message
Help us keep the archive clean and accurate. Reports are reviewed by a person – nothing is changed automatically.