Settings

The page will reload to apply your changes.
Theme

ASCII Art Font

ASCII Art Menu

Original Usenet thread from alt.ascii-art.animation, started 13 Feb 1994.
 _   _                     _        _             _     _           
| | | |___  ___ _ __   ___| |_     / \   _ __ ___| |__ (_)_   _____ 
| | | / __|/ _ \ '_ \ / _ \ __|   / _ \ | '__/ __| '_ \| \ \ / / _ \
| |_| \__ \  __/ | | |  __/ |_   / ___ \| | | (__| | | | |\ V /  __/
 \___/|___/\___|_| |_|\___|\__| /_/   \_\_|  \___|_| |_|_| \_/ \___|
vu.c: File viewer

vu.c: File viewer

alt.ascii-art.animation · 1 message · 13 Feb 1994
W Towle <csz...@scs.leeds.ac.uk> ASCII art 13 Feb 1994 23:54 · permalink
  As promised, my "vu" program.
(Comments welcome; I may do further work on it)

vu (v1.0) -- by Wm.Towle
Usage: vu [-c] [+d <delay>] [-l] <filename>

	-c: Don't count width or length
	+d: Add delay (slows down animations)
	-l: Don't "list" the file contents.

-----x8-----start vu.c-----
#include <stdio.h>
#include <ctype.h>

#define WAIT 500
typedef enum {FALSE,TRUE} bool;


/* Couple of global variables (yuk!)
 */
char escBuf[10];
int escBufPos;

void notlast(int* argnum, int argc)
{
	(*argnum)++;
	if (*argnum == argc)
	{
	    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;
	}
}

void main(int argc,char** argv)
{
 int argnum;
 FILE* inFile;
 char byte;
 bool openFail,escape,escOSB /* ESCAPE OPEN-SQUARE-BRACKET */;

 bool list = TRUE,count = TRUE;
 int lines,width,lwidth, pause=0,fpause;

	if (argc == 1)
	{
	    printf ("%s\n%s %s %s\n","vu (v1.0) -- by Wm.Towle",
		"Usage:", argv[0], "[-c] [+d <delay>] [-l] <filename>");
	    exit(0);
	}

	argnum = 1;

	if ( !(strcmp(argv[argnum],"-c")) )
	{
	    count = FALSE;
	    notlast(&argnum,argc);
	}
	if ( !(strcmp(argv[argnum],"+d")) )
	{
	    argnum++;
	    fpause=0;
	    while ( isdigit(argv[argnum][fpause]) )
	    {
		pause = (pause*10) + (argv[argnum][fpause] - '0');
		fpause++;
	    }
	    notlast(&argnum,argc);
	}   
	if ( !(strcmp(argv[argnum],"-l")) )
	{
	    list = FALSE;
	    notlast(&argnum,argc);
	}

	system ("stty -echo");

/* While loop next bit for multiple files, argnum<=argc */
	openFail = FALSE;
if (count)
	if ( (inFile = fopen(argv[argnum],"rb")) == NULL )
	{
	    printf ("%s %s\n", "vu: Can't open file", argv[argnum]);
	    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", argv[argnum]);
	    printf ("Width: %d\n", width);
	    printf ("Lines: %d\n", lines);
	    printf ("-----\n");
	    printf ("(RETURN:)");
	    do {scanf("%c",&byte);} while (byte!=10);
	    printf ("\n");
	}
if (list && !openFail)
	if ( (inFile = fopen(argv[argnum],"rb")) == NULL )
	{
	    printf ("%s %s\n", "vu: Can't open file", argv[argnum]);
	}
	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 (fpause = 0; fpause<pause*WAIT; fpause++);
	    } /* end of file. */
	}

	system ("stty echo");
}
-----x8-----end vu.c-----

::::
:: William "Wills" Towle :  csz...@scs.leeds.ac.uk (csz...@gps.leeds.ac.uk)
::                        Being blunt is pointless.

About this thread. These messages were posted publicly to the newsgroup alt.ascii-art.animation 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.