Software: Viewer Utility Source
From W Towle <csz...@scs.leeds.ac.uk>
· alt.ascii-art
· 20 Apr 1995 00:00 · View full thread
· report
Vu v2.0 ... Should compile better than my last effort :-) Better
than cat/type; has NEW (albeit limited and basic) file cutting ability.
Performs all operations in one pass, so doesn't need to make temporary
files. Removes unnecessary whitespace from ends of lines!
PS. You don't need to type the entire options, just enough of them!
Source is after this here manual page.
vu(1) Viewer Utility (v2.0) vu(1)
NAME
vu - viewer utility for text and animation (.vt) files
SYNOPSIS
vu [options] [file] [...]
DESCRIPTION
Vu can be used for working out the maximum dimension of text
files and for viewing animation and text files (slowing down
the output where appropriate). It has the additional feature
of removing unnecessary whitespace, and replaces "important"
tabs with whitespace in its output.
OPTIONS
-count Tells vu to compute width and height of files. There
is additional output given if the dimensions of what
was printed differed from the full dimensions.
-delay millisec
Specifies length of time to wait after printing each
character of the file
-head n Tells vu to only display the first n lines.
-length n
Tells vu to only display n lines.
-list Turns the displaying of the file off.
-reset Resets the options to default (for multiple files)
-start n
Specify the start line by number
FILES
~cszwt2/bin/vu
~cszwt2/ascart (.lha files within)
AUTHOR
William "Wills" Towle, csz...@scs.leeds.ac.uk
Page 1 (printed 4/20/95)
-----start vu.c-----x8
/*
* 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.
*/
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
void vu (char *argn, int strt, int lnth, int dlay, int calc, int list)
{
char *file= argn;
FILE *ifPtr;
char byte;
int show,
chop= 0, /* becomes true if we truncate somehow */
lines= 0,
lines_a= 0,
width_l= 0,
width= 0,
width_a= 0,
space= 0,
todo= lnth,
pipe= 0,
chrs,
i;
/* for -tail function, we need to copy piped input to temporary file */
/* strcpy(tempFile,tempnam("/tmp/", "vu")); */
pipe= (strcmp(file, "-")==0);
if ( pipe || ((!pipe) && (ifPtr= fopen(file, "rb"))) )
{
while ((pipe)? fread(&byte,sizeof(char),1,stdin)
: fread(&byte,sizeof(char),1,ifPtr))
{
show= (!(lines_a<strt)) && list;
if (show && lnth && (todo==0)) show= 0;
if ( (byte!=' ') && (byte!='\t') && (byte!='\n'))
{
for(i=0; i<space; i++) if (show) printf(" ");
width_l+=space;
space= 0;
}
switch (byte)
{
case '\t':
do {space++;}
while ((width_l+space)%8);
break;
case '\n':
if (space) chop= 1;
if (show)
{
printf ("\n");
if (todo) todo--;
lines++;
}
lines_a++;
break;
case ' ':
space++;
break;
default:
width_l++; if (show) printf ("%c", byte, width_l);
break;
}
if (dlay)
{
clock_t ticks= clock();
while (clock() < ticks+(dlay*CLOCKS_PER_SEC)/1000);
fflush(stdout);
}
if (byte=='\n')
{
if (width_l>width) width= width_l;
if (width_l+space>width_a) width_a= width_l+space;
width_l= 0; space= 0;
}
} /* end of file. */
if (space) chop= 1;
if (calc)
{
if (list) printf("--\n");
printf("Lines in file: %d\n", lines_a);
printf("Width of file: %d\n", width_a);
if (chop)
{
printf("Lines printed: %d\n", lines);
printf("Width printed: %d\n", width);
}
}
}
if (!pipe) fclose(ifPtr);
}
void warn1(const char *w1)
{
fprintf(stderr,"vu2: warning - %s\n", w1);
}
int strmatch(const char *s1, const char *s2)
{
int same=0,
i=0;
if (strlen(s1)<=strlen(s2))
while ( (i<strlen(s1)) && (s1[i]==s2[i]) )
{
same++; i++;
}
return (same>1);
}
void main(int argc,char** argv)
{
int arg,
strt=1, lnth=0, dlay=0, calc=0, list=1;
if (argc == 1)
{
printf ("%s\n%s %s %s\n",
"vu (v2.0) -- by Wm.Towle",
"Usage:", argv[0], "[options] {filename | - } [...]");
printf ("\n%s\n\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n%s\n",
"Options are:",
"-count\t: Work out file size (default: off)",
"-delay <n>: Add delay, duration n",
"-head <n>: First n lines",
"-length <n>: Number of lines to process",
"-list\t: Dont list the actual file (default: on)",
"-reset\t: Use default options",
"-start <n>: Specify start line by number",
"Use - on command line to read from a pipe");
exit(0);
}
for (arg= 1; arg<argc; arg++)
{
if (strmatch(argv[arg],"-count"))
{
calc= 1;
}
else if (strmatch(argv[arg],"-delay"))
{
arg++;
if ((arg<argc) && isdigit(argv[arg][0]))
dlay= atoi(argv[arg]);
else
warn1("delay parameter missing");
}
else if (strmatch(argv[arg],"-head"))
{
arg++;
if ((arg<argc) && isdigit(argv[arg][0]))
{
strt= 1;
lnth= atoi(argv[arg]);
}
else
warn1("head parameter missing");
}
else if (strmatch(argv[arg],"-length"))
{
arg++;
if ((arg<argc) && isdigit(argv[arg][0]))
lnth= atoi(argv[arg]);
else
warn1("length parameter missing");
}
else if (strmatch(argv[arg],"-list"))
{
list= 0;
}
else if (strmatch(argv[arg],"-reset"))
{
strt=1;
lnth=0;
dlay=0;
calc=0;
list=1;
}
else if (strmatch(argv[arg],"-start"))
{
arg++;
if ((arg<argc) && isdigit(argv[arg][0]))
strt= atoi(argv[arg]);
else
warn1("start parameter missing");
}
else if ( (strcmp(argv[arg],"-")==0) || (argv[arg][0]!='-') )
{
vu(argv[arg], strt, lnth, dlay, calc, list);
}
}
}
-----end vu.c-----x8
Someone give me a yell if the -delay doesn't work, or there's any other
silly bugs.
Cheers,
--
,. William "Wills" Towle : csz...@scs.leeds.ac.uk (csz...@gps.leeds.ac.uk)
`' "Eternal lying in a coffin waiting for you" ;-) - Ace of Base
Original message headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 124e6c,3f0d96a08722ae82,start X-Google-Attributes: gid124e6c,public X-Google-Thread: fbb9d,67924fb16802f2f2 X-Google-Attributes: gidfbb9d,public X-Google-Thread: f996b,3f0d96a08722ae82,start X-Google-Attributes: gidf996b,public X-Google-Thread: 110f55,3f0d96a08722ae82,start X-Google-Attributes: gid110f55,public From: csz...@scs.leeds.ac.uk (W Towle) Subject: Software: Viewer Utility Source Date: 1995/04/20 Message-ID: <3n6tka$8q...@gagme.wwa.com> X-Deja-AN: 101250462 approved: bob...@wwa.com sender: bob...@gagme.wwa.com references: <3mh3cf$jh...@gagme.wwa.com> organization: The University of Leeds, School of Computer Studies newsgroups: rec.arts.ascii,alt.ascii-art,alt.binaries.pictures.ascii,alt.binaries.pictures.utilities
Related ASCII art in the Gallery
Explore these categories from our collection of 11,000+ artworks:
//O\\
|\/\/\/| | | | | | (o)(o) C _) | ,___| | / /____\
|HHHHH/"\"\HHHHHHH| |HH`\|_.-)'|/'dP,H| |Hb.`\\_/_//'.oddH| |HHHb|`.\/\,'|HHHH| |HHHHHb/\/\/|HHHHH| |"""""""""""""""""| | |"" /\ \ / |"" | | |__/--\ \/ __| |
_________
/___ ___\
//@@@\ /@@@\\
\\@@@/ \@@@//
\___ " ___/
| - |
\_/ jrjc ______
/|_||_\`.__
( _ _ _\
=`-(_)--(_)-'
hjw .="=. _/.-.-.\_ ( ( o o ) ) |/ " \| \'---'/jgs /`"""`\\
Make your own ASCII art
Turn images, text or 3D into ASCII, or draw your own – right in your browser.
About this message.
This message was posted publicly to the newsgroup
alt.ascii-art
in 1995 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.
Report this message
Help us keep the archive clean and accurate. Reports are reviewed by a person – nothing is changed automatically.