UNIX FORTH for the VAX (part 5 of 8)

lwt1 at aplvax.UUCP lwt1 at aplvax.UUCP
Sat Jun 23 04:44:02 AEST 1984


Here is part 5 of 8 of the source for FORTH for the VAX.
Delete everything thru the "-- cut here --" line, and extract with 'sh':

	sh part1 part2 ... part7

where 'part?' are whatever you've named the files.  Note the copyright
notice at the end of README.  Please let us know how things go.  While
we can't support this software, we'll be posting bug fixes/upgrades to
net.sources as time permits.

Have fun!



						-John Hayes
						 Johns Hopkins University
						 Applied Physics Laboratory
						 ... seismo!umcp-cs!aplvax!lwt1

---------------------------------- cut here ----------------------------------
echo x - auto
cat >auto <<'!E!O!F'
" META1" FLOAD
" METAASM" FLOAD
" newforth"  -1 CREAT CLOSE
" newforth" 2 OPEN DUP . FORTH FILED !
0 WRN ! HOST
0 RAM   HEADS    METAMAP    METAWARN
" SYS:ASM" FLOAD
" META2" FLOAD
" SYS:SRC" FLOAD
DECIMAL 10000 CLEANUP
!E!O!F
echo x - format.c
cat >format.c <<'!E!O!F'
/*	
 *	Use:
 *		format [-l num] [-t file] [file file ... ]
 *
 *	This program formats records of arbitrary size and pretty-prints
 *	them.  Records are delimited by '\'.  A title is printed on each
 *	page and the records are separated by a line of dashes.  Records
 *	are prevented from spanning page boundaries.  The -l flag is used
 *	to specify the number of lines per page of your output device.
 *	The default is 63.  The -t flag is used to specify a file that
 *	contains a title that is to be printed on the top of each page.
 */

#include <stdio.h>

#define MAXLINES 15
#define LINELENGTH 120

	char title[10*LINELENGTH]="";	/* default: no title */
	int titlelen=0;

	int linesppage=63;		/* default: 63 lines per page */

main(argc,argv)
int argc;
char *argv[];
{
	char *s;
	FILE *fp;

	while (--argc>0 && **++argv=='-')
		switch (*(*argv+1)){
			case 't':
				argc--; argv++;
				if ((fp=fopen(*argv,"r"))!=NULL){
					s=title;
					while (fgets(s,LINELENGTH,fp)!=NULL){
						s+=strlen(s);
						titlelen++;
					}
					fclose(fp);
				}
				else fprintf(stderr,
                                        "format: can't open %s\n",*argv);
				break;
			case 'l':
				argc--; argv++;
				if (sscanf(*argv,"%d",&linesppage)==0)
					fprintf(stderr,
                                           "format: %s isn't a number\n",*argv);
				break;
			default:
				fprintf(stderr,
				   "format: bad flag %c\n",*(*argv+1));
				break;
		}
		if (argc>0)
			while (argc-- > 0){
				if ((fp=fopen(*argv,"r"))!=NULL){
					format(fp);
					fclose(fp);
				}
				else
					fprintf(stderr,
                                           "format: can't open %s\n",*argv);
				argv++;
			}
		else
			format(stdin);
}

format(input)
FILE *input;
{
	char buf[MAXLINES*LINELENGTH];
	char *bufp=buf;

	int nextline=0;

	while(fgets(bufp,LINELENGTH,input)!=NULL){
		if(*bufp!='\\'){
			nextline++;
			bufp+=strlen(bufp);
		}
		else {
			*bufp='\0';
			printrec(buf,nextline);
			bufp=buf;
			nextline=0;
		}
	}
}

printrec(lines,nlines)
char *lines;
int nlines;
{
	static int linect=1000;			/* absurd number forces
						   title on first page */

	int i;

	if (nlines+1 > linesppage-linect){
		printf("\f%s",title);
		linect=titlelen;
	}
	for (i=1; i<80; i++) putchar('-');
	printf("\n%s",lines);
	linect+=nlines+1;
}
!E!O!F
echo x - forth.1h
cat >forth.1h <<'!E!O!F'
.TH FORTH 1H
.SH NAME
forth
\- invoke a forth process.
.SH SYNOPSIS
forth
.SH DESCRIPTION
Forth invokes a FORTH-language process.  The process reads commands from the
standard input and sends results to the standard output.  If the standard 
input is a terminal, an interactive forth session results.  This is a subset
of FORTH-83 diverging only in the I/O.
.SH AUTHORS
J. Hayes
!E!O!F



More information about the Comp.sources.unix mailing list