Settings

The page will reload to apply your changes.
Theme

ASCII Art Font

ASCII Art Menu

Original Usenet thread from alt.ascii-art, started 20 Apr 1995.
 _   _                     _        _             _     _           
| | | |___  ___ _ __   ___| |_     / \   _ __ ___| |__ (_)_   _____ 
| | | / __|/ _ \ '_ \ / _ \ __|   / _ \ | '__/ __| '_ \| \ \ / / _ \
| |_| \__ \  __/ | | |  __/ |_   / ___ \| | | (__| | | | |\ V /  __/
 \___/|___/\___|_| |_|\___|\__| /_/   \_\_|  \___|_| |_|_| \_/ \___|
Software: Viewer Utility Source

Software: Viewer Utility Source

alt.ascii-art · 1 message · 20 Apr 1995
W Towle <csz...@scs.leeds.ac.uk> ASCII art 20 Apr 1995 00:00 · raw headers · 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

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

Help classify this post