Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10 5/3/83; site aplvax.UUCP
Path: utzoo!watmath!clyde!burl!hou3c!hocda!houxm!houxz!vax135!floyd!cmcl2!seismo!rlgvax!cvl!umcp-cs!aplvax!lwt1
From: lwt1@aplvax.UUCP
Newsgroups: net.sources
Subject: UNIX FORTH for the PDP11 (part 1 of 7)
Message-ID: <642@aplvax.UUCP>
Date: Fri, 8-Jun-84 15:55:10 EDT
Article-I.D.: aplvax.642
Posted: Fri Jun  8 15:55:10 1984
Date-Received: Sun, 10-Jun-84 00:48:06 EDT
Organization: JHU/Applied Physics Lab, Laurel, MD
Lines: 368

Here is part 1 of the source for FORTH for the PDP-11.
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.

VAX-FORTH should be 'forth'-coming {yuk-yuk} within a couple of weeks.

Have fun!



						-Lloyd W. Taylor
						 ... seismo!umcp-cs!aplvax!lwt1
---I will have had been there before, soon---

---------------------------------- cut here ----------------------------------
echo x - README
cat >README <<'+E+O+F'
.TL
Unix-FORTH for the PDP-11
.AU 
John R. Hayes
.AI
Applied Physics Lab
Johns Hopkins University
.ND
.PP
.bp
.PP
.UL Introduction.
FORTH running under unix is now available.  Typing 'forth'
from the terminal will invoke a FORTH process for you.  This memo describes
the unix specific features of this version of FORTH and how to boot the system.
The last section of 
this document deals entirely with unix-FORTH I/O programming.
.PP
Unix-FORTH is a subset of FORTH-83.  The only place that unix-FORTH
and FORTH-83 diverge is in the implementation of I/O.  It seems natural 
that a unix FORTH should take advantage of unix's elegant I/O structure
even at the cost of standardization.  Therefore, unix-FORTH is a process
that reads commands from its standard input and sends results to its standard
output.  If the standard input is the user's terminal, an interactive FORTH
session results.  Or a file of batch commands can be attached to the 
standard input and executed non-interactively.
.PP
A programmer used to typical FORTH systems will immediately note the
absence of FORTH screens.  FORTH screens are inadequate for managing
anything but the smallest programs and arbitrarily constrain software
modules to be sixteen lines long.  Unix-FORTH uses the unix file system and 
programs are created with any text editor.  Therefore, the entire unix 
toolbox is available for operation on FORTH source files.  Unix-FORTH
provides a set of I/O words that are very similar to their unix system-call
counterparts.  The user can have up to fifteen (system dependent) files
open simultaneously.
This, along with unix-FORTH's I/O implementation, allow the use of nested
loads.
.PP
A number of other enhancements are available to the user of unix-FORTH.
Any program resident in the unix file system can be executed from within
FORTH.  For example, to list the files in your current directory on the line
printer, you would type:
.DS L
     " ls | lpr" SYSTEM
.DE
A new subshell can be spawned
without disturbing your current FORTH environment by typing SHELL.  Typing
a ^C will cause FORTH to execute its warm start code.  This allows you
to terminate a program run amok without killing FORTH.  ^D (eof) will 
terminate the FORTH process.
.PP
.UL Bootstrapping.
Booting FORTH consists of two steps.  First, assemble the bootstrap system
with the command:
.DS L
 as -o bootforth  prim.as os.as
.DE
This will generate a FORTH subset system adequate for metacompiling the actual
system.  One potential problem with this step is the use of the PDP-11 extended
instruction set operations DIV and MUL.  If your machine lacks these 
instructions, you will have to code them yourself.  Bootforth is an executable
object file of a small FORTH system.  You might want to test it before going
on.
.PP
The second step consists of using  bootforth to metacompile the actual system.
Type:
.DS L
 bootforth 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.
This utility was developed independently from any UNIX or VENIX source code.
.SH "SEE ALSO"
Unix-FORTH for the TEGSE, TCE-T84-34
.SH AUTHORS
J. Hayes
+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 

#define MAXLINES 15
#define LINELENGTH 120

	char title[10*LINELENGTH]="";	/* default: not 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