[net.sources] Tek 41xx ditroff previewer posted

slaney@uiucme.UUCP (02/17/86)

This is my current version of a Tektronix previewer for ditroff output.  Any
ditroff output may be processed for (hopefully) all Tektronix 41xx terminal.
This program is different than tc.  tc is written for a 4015 terminal: a
different command set.

This version is far superior to the version posted to the net about 2 months
ago (previously called tk, now ditk).  This version is currently being used 
by secretaries here with great satisfaction.  Fifty page documents are checked 
routinely.  They report no errors.

I wish to thank the following people for their extended efforts:
		Phil Gross
		Paul Magelli
		Paul Pomes

short synopsis: (see also man page)
	supports all sizes of text
	uses hardware character fonts
	special fonts map to ascii equivalent; color changes
	some special characters supported
	line drawing supported
	circle/arc routine included in library; needs testing.
	character slant in library; needs testing.
	forward and backward paging (absolute and relative)
	displays any ditroff output (device independent previewer)
	Tek terminals that it works on (tested): 4107, 4109, 4113
	Tek terminals it should work on: 4111, 4115
	Tek terminals that lose features: 4105 (no zoom & pan)
					  4112 (no color)
	Tek terminals not listed I am unsure of
	certain wide characters (m,w) display narrower on the Tek terms than our
	  laser printer and phototypesetter; thus there may be a gap following
	  these letter.

Hints for performance:
	4105, 07, 09's will run at 38400 baud.  Makes text output fast.

command: ditk [-p#] ditroff.output
		p - page to begin at

To compile set the system type in ditk.c.  See note at top of ditk.c


Jeff [ihnp4!uiucdcs!uiucme!slaney; 217)333-9044]


-----Cut Here-----Cut Here-----Cut Here-----Cut Here-----
#!/bin/sh
# shar:	Shell Archiver
#	Run the following text with /bin/sh to create:
#	ditk.man
#	ditk.c
#	ditk.lib.c
#	Makefile
sed 's/^X//' << 'SHAR_EOF' > ditk.man
X.TH DITK 1
X.SH NAME
Xditk \- ditroff previewer for tektronix 41xx terminals
X.SH SYNOPSIS
X.B ditk
X[
X.BI \-p n
X]
X{
Xfile
X}
X.SH DESCRIPTION
X.I Ditk
Xallows previewing of
X.IR ditroff (1)
Xoutput on the Tektronix 41xx series graphic display terminals.
X.PP
XCommands:
X.PP
XTo get to the next page wait for the bell then type carriage return.
XTo get to an absolute page, type the number and a carriage return
Xafter the bell.
XTo move to a relative page type + or \- followed by the page difference. 
XThus +4 will move 4 pages forward.
X4 will move to page 4.
XRemember to follow these with a carriage return.
X.PP
XOn the last page a carriage return will exit the program.
XOn any page a 'q' will terminate the program.
XTo review all possible commands type '?'.
X.PP
XSpecifying the
X.BI \-p n
Xoption will cause
X.I ditk
Xto start on page number
X.IR n .
XThe default is 1.
X.SH BUGS
XNone known.
XPlease feel free to make additions and corrections.
XIf you make changes please ship a copy off to me,
Xihnp4!uiucdcs!uiucme!slaney (slaney%uiucme@a.cs.uiuc.edu (ARPAnet)).
X.SH NOTES
X.I Ditroff
Xcan be output to any of the following Tektronix terminals:  
X.IP
X4107, 4109, 4113.
X.PP
XThe following terminals will work but for hardware reasons lose certain
Xfeatures:
X.IN 5
X.sp
X.nf
X4105 - no retained segments, 8 colors
X4112 - black and white
X.IN -5
X.fi
X.PP
XThis program should work on the 4111 and the 4115, however ....
X(no guarantees.  See BUGS section above.)
XI have made what I believe is the only change necessary to get
X.I ditk
Xto run on a 4115.
XIt sets the coordinate mode to a 12 bit address instead of the 32 bit
Xaddressing.
XIt causes an error of level 0 on all other Tek devices.
XIt most likely won't be apparent. 
XThe warning begins "Terminal issues message ..." if it appears.
XCall it what you want.
X.PP
XThe program sets the fixup level of the Tektronix terminal to level 2.
XThis allows rapid deletion of the retained page of text.
XAt the end of 
X.I ditk
Xthe fixup level is set back to the default value of
X6.
X.PP
XThe features of this program are:
X.IP
XComplete device independence. 
XAll output from ditroff is capable of being processed independent
Xof what device it was intended for.
XNaturally somethings aren't perfect.
XThat's why this is called a previewer.
XIt is not intended for publications purposes. 
XOnly to give a good indication of correct form.
XIt provides a very convenient method of checking for orphans
Xand widows (lines).  
X.IP
XComplete character point size mapping.
X.IP
XFont changes are enabled by changing the color and displaying the ASCII
Xequivalent.
X.IP
XCurrently only straight line drawing.
XThe routine for arcs/circles is in the library included but
Xdraws circles starting from the right and proceeding counterclockwise. 
X.I Ditroff
Xlikes it from the left.
XIt may take some playing with.
X.IP
XCharacter slant is also possible.
XThe slant routine is included in ditk.lib.c.
XNeeds to be played with (see again the BUGS section).
X.IP
XComplete forward and backward paging.
X.SH IMPROVEMENTS
XAreas lacking for this program are:
X.IP
Xcircles
X.sp
Xcharacter slant
X.sp
Xspline fits
X.sp
Xsome special characters
X.SH AUTHOR
XJeff Slaney November 1985, helped by Philip Gross.
SHAR_EOF
echo 'Orignal Sum -> 13293 7 ditk.man'
echo 'Current Sum -> \c'
sum ditk.man
sed 's/^X//' << 'SHAR_EOF' > ditk.c
X#define USG
X/* #define BSD4.x */
X
X/*				NOTE
X   Need to define the system being used.  Currently defined for Bell (USG).  To
X   use on BSD remove the "#define USG" and the comment delimiters for 
X   "define BSD4.x".
X*/
X
X
X
X/* In order to perform random page output the input file must be read
X   sequentially.  Various text characteristics change and are not refreshed
X   with each new page.  To guarantee the correct text qualities all input
X   needs to be processed and certain qualities transmitted to the display
X   device.
X*/
X
X/*
Xoutput language from ditroff:
Xall numbers are character strings
X
Xsn      size in points
Xfn      font as number from 1-n
Xcx      ascii character x
XCxyz    funny char xyz. terminated by white space
XHn      go to absolute horizontal position n
XVn      go to absolute vertical position n (down is positive)
Xhn      go n units horizontally (relative)
Xvn      ditto vertically
Xnnc     move right nn, then print c (exactly 2 digits!)
X                (this wart is an optimization that shrinks output file size
X                 about 35% and run-time about 15% while preserving ascii-ness)
XDt ...\n        draw operation 't':
X        Dl x y          line from here by x,y
X        Dc d            circle of diameter d with left side here
X        De x y          ellipse of axes x,y with left side here
X        Da x y r        arc counter-clockwise by x,y of radius r
X        D~ x y x y ...  wiggly line by x,y then x,y ...
Xnb a    end of line (information only -- no action needed)
X        b = space before line, a = after
Xw       paddable word space (information only -- no action needed)
Xp       new page begins -- set v to 0
X#...\n  comment
Xx ...\n device control functions:
X        x i     init
X        x T s   name of device is s
X        x r n h v       resolution is n/inch
X                h = min horizontal motion, v = min vert
X        x p     pause (can restart)
X        x s     stop -- done for ever
X        x t     generate trailer
X        x f n s font position n contains font s
X        x H n   set character height to n
X        x S n   set slant to N
X
X        Subcommands like "i" are often spelled out like "init".
X*/
X
X#define TOP 3132
X#define ESC 27
X#define NULL 0
X#define ROUNDING 0
X#define TRUE 1
X#define FALSE 0
X
X#include <stdio.h>
X#include <ctype.h>
X#include <signal.h>
X#include <setjmp.h>
X#include <sys/types.h>
X
X#ifdef BSD4.x
X#include <sgtty.h>
Xstruct sgttyb ottyb, nttyb;
X#endif
X
X#ifdef USG
X#include <sys/termio.h>
Xstruct  termio old;
Xstruct  termio noret;
X#endif
X
XFILE *fp;                /* input file pointer */
Xchar c, *s;
Xchar *filename[30];
Xchar page_runner;       /* true if to not display characters; need to get to
X                           another page different than the current page */
Xchar first_page;
Xchar quit;
Xchar ignore_cr;
Xint i;
Xint currentx, currenty;
Xint absx, absy;
Xint point_size, raster_size, raster_height;
Xint char_width;
Xint char_space;
Xint resolution;
Xint current_page, next_page;
Xint     catchsig();
Xfloat rasters_per_point;
Xjmp_buf env;
Xint visibility[8];
X
X
Xmain(argc,argv)
Xint argc;
Xchar *argv[];
X{
X        /* initialize */
X        signal (SIGHUP, catchsig);
X        signal (SIGINT, catchsig);
X        signal (SIGQUIT, catchsig);
X        signal (SIGTERM, catchsig);
X        next_page = 1;
X        currentx = 0;
X        currenty = 0;
X        rasters_per_point = .6591;  /* set initially for a phototypesetter */
X        page_runner = FALSE;
X        first_page = TRUE;
X
X        if (argc < 2) {
X                printf("ditk [-p#] <ditroff.out>\n");
X                exit(1);
X        }
X
X        /* read all the options */
X        while (argc > 1 && argv[1][0] == '-'){
X                switch (argv[1][1]) {
X                case 'p':
X                        next_page = atoi(&argv[1][2]);
X                        page_runner = TRUE;
X                        break;
X                default:
X                        printf("Illegal option %c\n",*s);
X                        break;
X                }
X                argc--;
X                argv++;
X        }
X
X        if ((fp = fopen(*++argv,"r")) == NULL)
X        {
X                printf("Can't open %s\n", *argv);
X                exit(1);
X        }
X        *filename = *argv;
X
X        /* initialize the terminal */
X        /* put in tek mode */
X        select_code(0);
X        /* turn off the dialog area */
X        dialog_visib(0);
X        fixup_level(2);  /* set the fixup level to 2.  This allows for quick
X                                deletion of segments.  */
X        /* set coordinate mode to 12 bit format on 4115's 
X           gives an error on other terminals.  Error level of 0 */
X        coor_mode(0,0);
X        /* set the window */
X        set_window(0,0,4095,TOP);
X        page();
X        /* set the graphtext precision to stroke */
X        graphtx_prec(2);
X
X#ifdef BSD4.x
X        ioctl(0,TIOCGETP,(char *) &ottyb);
X        nttyb = ottyb;
X        nttyb.sg_flags |= CBREAK;
X        ioctl(0,TIOCSETP,(char *) &nttyb);
X#endif
X
X#ifdef USG
X        ioctl(0, TCGETA, &old);      /* set for reading characters from tty */
X        ioctl(0, TCGETA, &noret);
X        noret.c_lflag &= ~ICANON;
X        ioctl(0, TCSETA, &noret);
X#endif
X
X        quit = FALSE;
X        c = getc(fp);
X        if (c == EOF) quit = TRUE;
X        setjmp (env);
X        while (quit == FALSE) {
X                switch(c) {
X
X                case 'p':
X                        current_page = ctoi();
X                        ignore_cr = FALSE;
X                        if (current_page != next_page)
X                                break;
X                        if (page_runner == FALSE) {
X                                /* close off all open segments for next page */
X                                if (first_page == TRUE) {
X                                        next_page = next_page + 1;
X                                        del_segment(-1);
X                                        page();
X                                        first_page = FALSE;
X                                }
X                                else {
X                                        end_segment();
X                                        printf("%c",7); /* signal end of page */
X                                        fflush(stdout);
X                                        /*readch();*/
X                                        readresponse();
X                                        del_segment(-1);
X                                        page();
X                                        if (next_page < current_page) {
X                                                fclose(fp);
X                                                fp = fopen(*argv,"r");
X                                                page_runner = TRUE;
X                                                break;
X                                        }
X                                        else if (next_page > current_page) {
X                                                page_runner = TRUE;
X                                                break;
X                                        }
X                                        else next_page = current_page +1;
X                                        if (c == EOF) {
X                                                next_page = 1;
X                                                fclose(fp);
X                                                fp = fopen(*argv,"r");
X                                                del_segment(-1);
X                                                page();
X                                                page_runner = TRUE;
X                                                break;
X                                        }
X                                }
X                        }
X                        else {   /* page_runner == TRUE */
X                                first_page = FALSE;
X                                page_runner = FALSE;
X                                next_page = next_page + 1;
X                        }
X                        /* don't clear screen: leave dialog area alone */
X                        /* open retained segment 1 */
X                        begin_seg(1);
X                        /* draw a line down the right margin */
X                        move(2420,0);
X                        draw(2420,TOP);
X                        move(currentx,currenty);
X                        break;
X
X                case 's':
X                        /* point size */
X
X                        /*  The font size is determined only by the terminal
X                        being used.  The device formatted for does not enter
X                        in.   A simple conversion is all that is needed.
X                        72(points/inch) * 11(inches/page) = 792(points/page)
X                        3132(rasters/page) * 1/792(page/points) =
X                                                        3.95(rasters/point)
X                                point size 1 = raster size 3.95
X                        */
X
X                        point_size = ctoi();
X                        raster_size = point_size * 3.95 + ROUNDING;
X                        char_width = raster_size * .4 + ROUNDING;  /* it looks good */
X                        raster_height = .75 * raster_size;
X                        char_space = 1.2 * raster_size + ROUNDING; /* close to default */
X                        graphtx_size(char_width,raster_height,char_space);
X                        break;
X
X                case 'f':       /* font change */
X                        ignore_cr = FALSE;
X                        text_index(ctoi());             /* just change color */
X                        break;
X
X                case 'h':       /* relative horizontal move */
X                        absx = absx + ctoi();
X                        if (page_runner == TRUE)
X                                break;
X                        currentx = absx * rasters_per_point + ROUNDING;
X                        move(currentx,currenty);
X                        break;
X
X                case 'v':       /* relative move vertical */
X                        absy = absy + ctoi();
X                        if (page_runner == TRUE)
X                                break;
X                        currenty = TOP - absy * rasters_per_point + ROUNDING;
X                        move(currentx,currenty);
X                        break;
X
X                case 'H':
X                        /* absolute horizontal move */
X                        ignore_cr = FALSE;
X                        absx = ctoi();
X                        if (page_runner == TRUE)
X                                break;
X                        currentx = absx * rasters_per_point + ROUNDING;
X                        move (currentx,currenty);
X                        break;
X
X                case 'V':
X                        /* absolute vertical */
X                        ignore_cr = FALSE;
X                        absy = ctoi();
X                        if (page_runner == TRUE)
X                                break;
X                        currenty = TOP - absy * rasters_per_point + ROUNDING;
X                        move(currentx,currenty);
X                        break;
X
X                case 'c':
X                        /* character */
X                        /* display next character */
X                        c = getc(fp);
X                        if (page_runner == TRUE)
X                                break;
X                        printf("%cLT1%c",ESC,c);
X                        break;
X
X                case 'C':
X                        /* special character */
X                        if (page_runner == TRUE){
X                                c = getc(fp);
X                                c = getc(fp);
X                                break;
X                        }
X                        c = getc(fp);
X                        if (c == '\n') c = getc(fp);  /* remove newlines */
X                        switch(c){
X                        case 'r':
X                                c = getc(fp);
X                                if (c == '\n') c = getc(fp);  /* remove newlines */
X                                if (c == 'u')  /* underline */
X                                        printf("%cLT1_",ESC);
X                                break;
X                        case 'F':       /* fancy ff's */
X                                printf("%cLT1f",ESC);
X                                currentx = currentx + char_space * .2 + ROUNDING;
X                                move(currentx,currenty);
X                                printf("%cLT1f",ESC);
X                                c = getc(fp);
X                                if (c == '\n') c = getc(fp);  /* remove newlines */
X                                currentx = currentx + char_space * .2 + ROUNDING;
X                                move(currentx,currenty);
X                                printf("%cLT1%c",ESC,c);
X                                break;
X                        case 'f':       /* fancy f's */
X                                printf("%cLT1f",ESC);
X                                currentx = currentx + char_space * .2 + ROUNDING;
X                                move(currentx,currenty);
X                                c = getc(fp);
X                                if (c == '\n') c = getc(fp);  /* remove newlines */
X                                printf("%cLT1%c",ESC,c);
X                                break;
X                        case 'h':       /* hypen */
X                                c = getc(fp);
X                                if (c == '\n') c = getc(fp);  /* remove newlines */
X                                c = '-';
X                                printf("%cLT1%c",ESC,c);
X                                break;
X                        case 'd':       /* Cde is a degree sign */
X                                currenty = currenty + raster_height * .4;
X                                currentx = currentx + char_width * .5;
X                                move(currentx,currenty);
X                                c = getc(fp);
X                                if (c == '\n') c = getc(fp);
X                                    /* remove newlines */
X                                c = 'o';
X                                printf("%cLT1%c",ESC,c);
X                                currenty = currenty - raster_height * .4;
X                                currentx = currentx - char_width * .5;
X                                move(currentx,currenty);
X                                break;
X                                
X                        default:
X                                while ((c = getc(fp)) != '\n' );
X                                break;
X                        }
X                        break;
X
X                case '0':
X                case '1':
X                case '2':
X                case '3':
X                case '4':
X                case '5':
X                case '6':
X                case '7':
X                case '8':
X                case '9':
X                        /* horizontal relative displacement */
X                        ignore_cr = TRUE;
X                        while ((c >= '0') && (c <= '9')){
X                                absx = absx + (c - '0') * 10;
X                                c = getc(fp);
X                                if (c == '\n') c = getc(fp);
X                                   /* remove any newlines */
X                                absx = absx + (c - '0');
X                                c = getc(fp);
X                                if (c == '\n') c = getc(fp);
X                                   /* remove any newlines */
X                                if (page_runner != TRUE) {
X                                        currentx = absx * rasters_per_point + ROUNDING;
X                                        move(currentx,currenty);
X                                        printf("%cLT1%c",ESC,c);
X                                }
X                        c = getc(fp);
X                        if (c == 'w') c = getc(fp);  /* ignore 'w' */
X                        } /* while */
X                        ungetc(c,fp);
X                        break;
X
X                case 'x':
X                        c=getc(fp); /* this should be a blank */
X                        switch(getc(fp)){
X                        case 'r':  /* set the resolution translation
X                                                                                factor */
X                                /* there are 3 numbers on this line.  they
X                                   are (1) resolution in points per inch
X                                       (2) minimum horizontal motion
X                                       (3) minimum vertical motion
X                                   Only concerned with the resolution in points
X                                   per inch.  Call the term "resolution".
X
X                                   How to determine the mapping from ANY device
X                                   to the Tek terminal.
X
X                resolution(points/inch) * 11(inches/page) = (points/page)
X
X                3132(rasters/page) * (page/points) = (rasters/point)
X
X                motion of 1 point equals X rasters on the Tek.
X
X                                   */
X
X                                while(isalpha(c=getc(fp)));
X                                resolution = ctoi();
X                                rasters_per_point = 3132.0 / (11.0 * resolution);
X                                while ((c = getc(fp)) != '\n' );
X                                /* ignore the rest of line */
X                                break;
X
X                        default:
X                                /* ignore all other device control for now */
X                                while ((c = getc(fp)) != '\n' );
X                                break;
X                        } /* switch */
X                        break;
X
X                case 'D':
X                        if (page_runner == TRUE)
X                                break;
X                        switch(getc(fp)){
X                        case 'l':
X                                /* draw line from current to x,y */
X                                move(currentx,currenty);
X                                absx = absx + ctoi();
X                                currentx = absx * rasters_per_point + ROUNDING;
X                                absy = absy + ctoi();
X                                currenty = TOP - absy * rasters_per_point;
X                                draw(currentx,currenty) + ROUNDING;
X                                while ((c = getc(fp)) != '\n');
X                                break;
X
X                        default:
X                                break;
X                        }       /* switch */
X
X                        break;
X
X                case 'n':
X                        ignore_cr = FALSE;
X                        ctoi();         /* remove b */
X                        ctoi();         /* remove a */
X                        /* while (( c = getc(fp)) != '\n');  
X                                                /* ignore rest of line */
X                        break;
X
X                default:
X                        break;
X
X                } /* switch */
X                c = getc(fp);
X                if ((c == EOF) && (page_runner == TRUE)) {
X                        next_page = 1;
X                        fclose(fp);
X                        fp = fopen(*argv,"r");
X                        del_segment(-1);
X                        page();
X                        page_runner = TRUE;
X                }
X                if ((c == EOF) && (page_runner == FALSE)) {
X                        end_segment();  /* close out segments */
X                        printf("%c",7); /* signal at the end with a bell */
X                        fflush(stdout);
X                        quit = TRUE;
X                        readresponse();
X                        if (quit == FALSE) {
X                                fclose(fp);
X                                fp = fopen(*argv,"r");
X                                del_segment(-1);
X                                page_runner = TRUE;
X                                page();
X                                c = getc(fp);
X                        }
X                }
X        }
X
X        /* set terminal back */
X        visibility[0] = 1;
X        visibility[1] = 1;      /* turn graphics plane on to gauranttee not
X                                        killed in help area */
X        surf_visib(2,visibility);
X        del_segment(-1);        /* erase retained segments */
X        page();
X        fixup_level(6);         /* set fixup level back to default */
X        clear_dialog();
X        dialog_visib(1);        /* turn the dialog area on*/
X        select_code(1);         /* put in ansi mode */
X#ifdef BSD4.x
X        ioctl(0,TIOCSETP,(char *) &ottyb);
X#endif
X#ifdef USG
X        ioctl(0, TCSETA, &old);         /* set tty back */
X#endif
X} /* tk */
X
X
Xctoi()
X{
X        int i, n , sign;
X        char s;
X
X        s = ' ';
X        while (s == ' ' || s == '\n' || s == '\t')
X                s = getc(fp);   /* skip white space */
X        sign = 1;
X        if (s == '+' || s == '-') {     /* sign */
X                sign = (s == '+') ? 1 : -1;
X                s = getc(fp);
X        }
X        n = 0;
X        while (s >= '0' && s <= '9'){
X                n = 10 * n + s - '0';
X                s = getc(fp);
X                if ((s == '\n') && (ignore_cr == TRUE)) s = getc(fp);
X        }
X        ungetc(s,fp);
X        return(sign * n);
X}
X
X
Xreadresponse()
X{
X        int n;
X        int delta_page;
X        char s;
X
X        read(0, &s, 1);
X        while(s != '\n')
X                switch(s){
X                case '0': 
X                case '1': 
X                case '2': 
X                case '3': 
X                case '4':
X                case '5': 
X                case '6': 
X                case '7': 
X                case '8': 
X                case '9':
X                        next_page = 0;
X                        while (s >= '0' && s <= '9'){
X                                next_page = 10 * next_page + s - '0';
X                                read(0, &s, 1);
X                        }
X                        s = '\n';
X                        quit = FALSE;
X                        break;
X                case '+':
X                        delta_page = 0;
X                        s = getchar();
X                        while (s >= '0' && s <= '9'){
X                                delta_page = 10 * delta_page + s - '0';
X                                read(0, &s, 1);
X                        }
X                        if (delta_page == 0) delta_page = 1;
X                        next_page = next_page + delta_page - 1;
X                        s = '\n';
X                        quit = FALSE;
X                        break;
X                case '-':
X                        delta_page = 0;
X                        read(0, &s, 1);
X                        while (s >= '0' && s <= '9'){
X                                delta_page = 10 * delta_page + s - '0';
X                                read(0, &s, 1);
X                        }
X                        if (delta_page == 0) delta_page = 1;
X                        next_page = next_page - delta_page - 1;
X                        s = '\n';
X                        quit = FALSE;
X                        break;
X                case 'H':       /* provide help */
X                case 'h':
X                case '?':
X                        visibility[0] = 1;
X                        visibility[1] = 0;      /* turn graphics plane off */
X                        surf_visib(2,visibility);
X                        dialog_visib(1);        /* turn on the dialog area */
X                        clear_dialog();
X                        print_help();
X                        read(0, &s, 1);
X                        /* turn off the dialog area */
X                        dialog_visib(0);        /* turn off the dialog area */
X                        visibility[0] = 1;
X                        visibility[1] = 1;      /* turn graphics plane on */
X                        surf_visib(2,visibility);
X                        printf("dialog area off; graphics plane on\n");
X                        read(0, &s, 1);
X                        break;
X                case 'k':
X                case 'K':       /* who uses k to quit? */
X                case 'q': 
X                case 'Q':
X                        quit = TRUE;
X                        s = '\n';
X                        break;
X                case ' ':
X                case '\n':
X                        s = '\n';
X                        break;
X                default:
X                        read(0, &s, 1);
X                        break;
X                } /* switch */
X} /* readresponse */
X
Xprint_help(){
X        printf("\n\n\n\n\n\n    The options available are:\n\n\n");
X        printf("\tcarriage return,\n");
X        printf("\tspace         to go to next page\n");
X        printf("\t#CR           absolute page to go to, # an integer, CR - carriage return\n");
X        printf("\t+#CR,-#CR     relative page to go to, # an integer, CR - carriage return\n");
X        printf("\th,H,?         for this page\n");
X        printf("\tq,Q,k,K       to quit\n");
X        printf("\n\tCarriage Return and space perform the same function\n");
X        printf("\tBackspacing does not work.\n");
X        printf("\n\n\tAny key to continue: ");
X        }
X
Xreadch(){
X        char c;
X        if (read(2,&c,1)<1) c = 0;
X        return(c);
X}
X
Xcatchsig ()
X{
X        signal (SIGINT, SIG_IGN);
X        quit = TRUE;
X        longjmp (env, 1);
X}
X
X
SHAR_EOF
echo 'Orignal Sum -> 44369 50 ditk.c'
echo 'Current Sum -> \c'
sum ditk.c
sed 's/^X//' << 'SHAR_EOF' > ditk.lib.c
X/*
X		Written by Jeff Slaney November 1985 
X				helped by Phil Gross
X
X*/
X
X#define ESC 27
X
X/* Tektronix 4110 Series Command Reference, p. 7-226, 12/11/85, jrs */
X/* Only valid for Tektronix 4115 terminals */
Xcoor_mode(mode,size)
Xint mode;
X{
X	printf("%cUX",ESC);
X	trans_int(mode);
X	trans_int(size);
X}
X
X/* Tektronix 4110 Series Command Reference, p. 7-191, 2/29/84, phg */
Xselect_code(mode)
Xint mode;
X{
X	if (mode == 0)
X		printf("%c%%\!0",ESC);
X	else if (mode == 1)
X		printf("%c%%\!1",ESC);
X	else
X		printf("%c%%\!2",ESC);
X}
X
X/* Tektronix 4110 Series Command Reference, p. 7-251, 2/29/84, phg */
Xfixup_level(level)
Xint level;
X{
X	printf("%cRF",ESC);
X	trans_int(level);
X}
X
X/* Tektronix 4110 Series Command Reference, p. 7-40, 2/28/84, phg */
Xclear_dialog()
X{
X	printf("%cLZ",ESC);
X}
X
X/* Tektronix 4110 Series Command Reference, p. 7-237, 2/29/84, phg */
Xdialog_visib(status)
Xint status;
X{
X	printf("%cLV",ESC);
X	trans_int(status);
X}
X
X
X/* Tektronix 4110 Series Command Reference, p. 7-356, 2/29/84, phg */
Xsurf_visib(elems, arr)
Xint elems, arr[];
X{
X	printf("%cRI",ESC);
X	int_array(elems, arr);
X}
X
X/* Tektronix 4110 Series Command Reference, p. 7-360, 2/29/84, phg */
Xtext_index(text)
Xint text;
X{
X	printf("%cMT",ESC);
X	trans_int(text);
X}
X
X
X/* Tektronix 4110 Series Command Reference, p. 7-276, 2/29/84, phg */
Xgraphtx_size(width, height, space)
Xint width, height, space;
X{
X	printf("%cMC",ESC);
X	trans_int(width);
X	trans_int(height);
X	trans_int(space);
X}
X
X
X/* Tektronix 4110 Series Command Reference, p. 7-277, 2/29/84, phg */
Xgraphtx_slnt(angle)
Xfloat angle;
X{
X	printf("%cMA",ESC);
X	trans_real(angle);
X}
X
X
X/* Tektronix 4110 Series Command Reference, p. 7-270, 2/29/84, phg */
Xgraphtx_font(font)
Xint font;
X{
X	printf("%cMF",ESC);
X	trans_int(font);
X}
X
X
X/* Tektronix 4110 Series Command Reference, p. 7-274, 2/29/84, phg */
Xgraphtx_prec(precision)
Xint precision;
X{
X	printf("%cMQ",ESC);
X	trans_int(precision);
X}
X
X
X/* Tektronix 4110 Series Command Reference, p. 7-275, 2/29/84, phg */
Xgraphtx_rot(angle)
Xfloat angle;
X{
X	printf("%cMR",ESC);
X	trans_real(angle);
X}
X
X
X/* Tektronix 4110 Series Command Reference, p. 7-91, 2/29/84, phg */
Xend_segment()
X{
X	printf("%cSC",ESC);
X}
X
X
X/* Tektronix 4110 Series Command Reference, p. 7-55, 2/29/84, phg */
Xdel_segment(segment)
Xint segment;
X{
X	printf("%cSK",ESC);
X	trans_int(segment);
X}
X
X
X/* Tektronix 4110 Series Command Reference, p. 7-23, 2/28/84, phg */
Xbegin_seg(segment_num)
Xint segment_num;
X{
X	printf("%cSO",ESC);
X	trans_int(segment_num);
X}
X
X/* Tektronix 4110 Series Command Reference, p. 7-140, 2/29/84, phg */
Xpage()
X{
X	printf("%c%c",ESC,12);  /* ESCAPE and a CONTROL L */
X}
X
X
X/* Tektronix 4110 Series Command Reference, p. 7-370, 2/29/84, phg */
Xset_window(llx, lly, urx, ury)
Xint llx, lly, urx, ury;
X{
X	printf("%cRW",ESC);
X	trans_xy(llx, lly);
X	trans_xy(urx, ury);
X}
X
X
X#include <math.h>
Xfloat torads();
Xarc(x, y, r, st, sp, point)
Xint x, y, r, point;
Xfloat st, sp;
X/* x and y are the center of the circle
X * r is the radius of the arc
X * st is the starting degree angle of the arc
X * sp is the stopping degree angle of the arc
X * point is how many points along the arc are plotted
X */
X{
X	int t1, t2;
X	float k, inc;
X	t1 = x + (r * cos(torads(st)));
X	t2 = y + (r * sin(torads(st)));
X	move(t1, t2);
X	inc = (sp - st)/ point;
X	for ( k = inc; k < (sp - st); k += inc) {
X		t1 = (x + r * cos(torads(st + k)));
X		t2 = (y + r * sin(torads(st + k)));
X		draw(t1, t2);
X	}
X	t1 = (x + r * cos(torads(sp)));
X	t2 = (y + r * sin(torads(sp)));
X	draw(t1, t2);
X}
X
X/* converts degrees to radians */
Xfloat torads(coord)
Xfloat coord;
X{
X	return(3.1415962/180.0 * coord);
X}
X
X
X/* Tektronix 4110 Series Command Reference, p. 7-137, 2/29/84, phg */
Xmove(x, y)
Xint x, y;
X{
X	printf("%cLF",ESC);
X	trans_xy(x, y);
X}
X
X
X
X/* Tektronix 4110 Series Command Reference, p. 7-72, 2/29/84, phg */
Xdraw(x, y)
Xint x, y;
X{
X	printf("%cLG",ESC);
X	trans_xy(x, y);
X}
X
X
X/* Tektronix 4110 Series Command Reference, p. 7-391, 2/29/84, phg */
X/* translate coords to something the tek likes */
Xtrans_xy(x, y)
Xint x, y;
X{
X	int t, arr[5];
X	arr[0] = 0040 | getbits(y, 11, 5);
X	arr[1] = 0140 | (getbits(y, 1, 2) << 2) | getbits(x, 1, 2);
X	arr[2] = 0140 | getbits(y, 6, 5);
X	arr[3] = 0040 | getbits(x, 11, 5);
X	arr[4] = 0100 | getbits(x, 6, 5);
X	for (t = 0; t <= 4; t++)
X		printf("%c", arr[t]);
X}
X
X
X/* Tektronix 4110 Series Command Reference, p. 7-160, 3/19/84, phg */
Xtrans_real(decimal)
Xfloat decimal;
X{
X	float epsilon = 0.00006104;
X	float temp;
X	int trunc, neg_flag, mantissa, exponent;
X	temp = decimal;
X	neg_flag = 0;
X	if (temp < 0) {
X		neg_flag = -1;
X		temp = neg_flag * temp;
X	}
X	trunc = temp / 1;
X	while ( temp > (trunc + epsilon) && trunc < 16383) {
X		temp = temp * 2.0;
X		exponent--;
X		trunc = temp / 1;
X	}
X	while (temp > 32767.0) {
X		temp = temp / 2.0;
X		exponent++;
X	}
X	mantissa = (temp + 0.5) / 1;
X	if (neg_flag == -1)
X		mantissa = -mantissa;
X	trans_int(mantissa);
X	trans_int(exponent);
X}
X
X
X
X/* Tektronix 4110 Series Command Reference, p. 7-129, 3/19/84, phg */
X/* prints a tek translated integer */
Xtrans_int(x)
Xint x;
X{
X	int t, arr[3];
X	if ((t = getbits(x, 31, 1)) == 1) {
X		x = ~x + 0001;
X		arr[2] = 0040 | getbits(x, 3, 4);
X	}
X	else
X		arr[2] = 0060 | getbits(x, 3, 4);
X	arr[0] = 0100 | getbits(x, 15, 6);
X	arr[1] = 0100 | getbits(x, 9, 6);
X	if (arr[0] != '@') {
X		putchar(arr[0]);
X		putchar(arr[1]);
X		putchar(arr[2]);
X	}
X	else if (arr[1] != '@') {
X		putchar(arr[1]);
X		putchar(arr[2]);
X	}
X	else if (arr[2] != '@')
X		putchar(arr[2]);
X}
X
X
X
X/* This routine returns the value of n bits beginning with the p'th bit of x */
X/*
X *	t = getbits(57, 5, 3)
X *	(x = 57
X *	x = 01110111
X *	p = 5, n = 3
X *	x = 00000110
X *	x = 6)
X *	t = 6
X */
Xgetbits(x, p, n)
Xunsigned x, p, n;
X{
X	return((x >> (p+1-n)) & ~(~0 << n));
X}
X
X
X/* Tektronix 4110 Series Command Reference, p. 7-6, 3/19/84, phg */
X/* prints a character string after printing a count */
X#include <stdio.h>
Xchar	*rmtb;
X
Xtrans_char(string)
Xchar string[];
X{
X	int char_len;
X	int i;
X
X	rmtb = string;
X	i = strlen(string) - 1;
X	while (rmtb[i] == ' ')
X		i--;
X	rmtb[++i] = '\0';
X	trans_int(i);
X	printf("%s", rmtb);
X}
X
X/* Tektronix 4110 Series Command Reference, p. 7-6, 3/19/84, phg */
X/* routine to transmit an encoded array */
Xint_array(elems, array)
Xint elems, array[];
X{
X	int i;
X	trans_int(elems);
X	for (i = 0; i < elems; i++) {
X		trans_int(array[i]);
X	}
X}
SHAR_EOF
echo 'Orignal Sum -> 13959 13 ditk.lib.c'
echo 'Current Sum -> \c'
sum ditk.lib.c
sed 's/^X//' << 'SHAR_EOF' > Makefile
Xditk: ditkofiles
X	cc -O ditk.o ditk.lib.o -lm -o ditk
X.c.o:
X	cc -c $<
Xditkfiles: ditk.c ditk.lib.c
Xditkofiles: ditk.o ditk.lib.o
SHAR_EOF
echo 'Orignal Sum -> 10718 1 Makefile'
echo 'Current Sum -> \c'
sum Makefile
exit